Learn R Programming

nanonext (version 0.5.4)

sha512: Cryptographic Hashing Using the SHA-512 Algorithm

Description

Returns a SHA-512 hash or HMAC of the supplied R object. Uses the optimised implementation from the Mbed TLS library.

Usage

sha512(x, key = NULL)

Value

A 'nanoHash' object - raw vector of length 64.

Arguments

x

an object.

key

(optional) supply a secret key to generate an HMAC. If missing or NULL, the SHA-512 hash of 'x' is returned.

Details

For arguments 'x' and 'key', a raw vector is hashed directly, a character string is converted using charToRaw, whilst other objects are serialised first.

Use as.character() to convert the returned raw vector to a single character string.

Examples

Run this code
sha512("hello world!")

# Converts to a character string:
as.character(sha512("hello world!"))

# Obtain HMAC:
sha512("hello world!", "SECRET_KEY")

Run the code above in your browser using DataLab