Cryptographic Functions

This page covers the various cryptographic functions supported by Rockset.

Note that the functions in this page take bytes arguments and return bytes values. You may pass in a string as argument (it will be encoded as UTF-8), and you may convert the returned bytes to string using, for instance, TO_HEX().

#Hash Functions

#HASH

HASH(x, digest)

Computes the hash of the bytes value x using digest, where digest is one of the OpenSSL digest methods md5, sha1, sha256, or sha512 (case insensitive).

SELECT
    HASH('foo', 'md5')
'rL0Y20zC+Fzt72VPzMSk2A=='
SELECT
    HASH('foo', 'sha1')
'C+7Hteo/D9vJXQ3UfzxbwnXaijM='
SELECT
    HASH('foo', 'sha256')
'LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564='
SELECT
    HASH('foo', 'sha512')
'9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuKCxBvl5CVNiCB3LFUYosWowMf37aGVlKfrU5RT4e1w=='

#MD5

MD5(x)

Computes the MD5 hash of the bytes value x.

SELECT
    MD5('foo')
'rL0Y20zC+Fzt72VPzMSk2A=='
SELECT
    MD5('')
'1B2M2Y8AsgTpgAmY7PhCfg=='
SELECT
    MD5(null)
null

#SHA1

SHA1(x)

Computes the SHA1 hash of the bytes value x.

SELECT
    SHA1('foo')
'C+7Hteo/D9vJXQ3UfzxbwnXaijM='
SELECT
    SHA1('')
'2jmj7l5rSw0yVb/vlWAYkK/YBwk='
SELECT
    SHA1(null)
null

#SHA256

SHA256(x)

Computes the SHA256 hash of the bytes value x.

SELECT
    SHA256('foo')
'LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564='
SELECT
    SHA256('')
'47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='
SELECT
    SHA256(null)
null

#SHA512

SHA512(x)

Computes the SHA512 hash of the bytes value x.

SELECT
    SHA512('foo')
'9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuKCxBvl5CVNiCB3LFUYosWowMf37aGVlKfrU5RT4e1w=='
SELECT
    SHA512('')
'z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=='
SELECT
    SHA512(null)
null

#HMAC Functions

#HMAC_MD5

HMAC_MD5(x, key)

Computes the MD5 HMAC of the bytes value x using key as the key.

SELECT
    HMAC_MD5('foo', 'bar')
'Mbbbnl60rdtC8abKBzZ63A=='
SELECT
    HMAC_MD5('foo', null)
null

#HMAC_SHA1

HMAC_SHA1(x, key)

Computes the SHA1 HMAC of the bytes value x using key as the key.

SELECT
    HMAC_SHA1('foo', 'bar')
'hdFVxV7ShqMAvRzxJN4I2H6RTzo='
SELECT
    HMAC_SHA1('foo', null)
null

#HMAC_SHA256

HMAC_SHA256(x, key)

Computes the SHA256 HMAC of the bytes value x using key as the key.

SELECT
    HMAC_SHA256('foo', 'bar')
'FHkzIYqqvAuLEKKzpcNGhMjZQ0G88QpHNtxycPd0GFE='
SELECT
    HMAC_SHA256('foo', null)
null

#HMAC_SHA512

HMAC_SHA512(x, key)

Computes the SHA512 HMAC of the bytes value x using key as the key.

SELECT
    HMAC_SHA512('foo', 'bar')
'JCV9chBYKmXHMexVFZyBhMwkwCSJRT5YWH9x9EwjotYbS3IVSonRey1JRIqEUuoGb0/FaivOrUXAiFcv/M2z2A=='
SELECT
    HMAC_SHA512('foo', null)
null

#HMAC

HMAC(x, key, digest)

Computes the HMAC of the bytes value x using key as the key and digest as the digest method, where digest is is one of the OpenSSL digest methods md5, sha1, sha256, or sha512 (case insensitive).

SELECT
    HMAC('foo', 'bar', 'md5')
'Mbbbnl60rdtC8abKBzZ63A=='
SELECT
    HMAC('foo', 'bar', 'sha256')
'FHkzIYqqvAuLEKKzpcNGhMjZQ0G88QpHNtxycPd0GFE='
Join us on Slack!
Building on Rockset? Come chat with us!