Skip to content

HMAC_KS

Use a secret defined by an encryption key to run the HMAC function.

HMAC_KS(string, key [, algorithm])
string
Specify a character string or an expression that evaluates to a character string.
key
Specify the name of an encryption key, as defined with the CREATE KEY command. The secret associated with this key will be used to run the function. Users of this function must be granted HMAC privilege on the key. See ON KEY.
algorithm
Optionally, specify 1 or 2. The default is 2. See HMAC.

The return type of this function is VARCHAR(128).

Examples

For example:

premdb=# grant hmac on key playerkey to bobr;
GRANT
premdb=# \c premdb bobr
You are now connected to database "premdb" as user "bobr".
premdb=> select hmac_ks(nickname,playerkey,2) from team order by teamid limit 3;
                            hmac_ks                              
------------------------------------------------------------------
 b28f48afa05c480db5f6ade36d6c79636ba0ad7b0cfd81b7f45de139da7927e8
 f7da1a52b3d6a0613a0ee654c3a02bd900cc15a0ac52d6ad5e4db84c68b92380
 5bc029cf8e0be0cadc026e01cfc88209bba7a24cb01eebed400cd29d323dfb3f
(3 rows)

Parent topic:String Functions