function

hmac . string . sncode

VERSION5.106 Compute HMAC

HMAC(1e)

NAME

hmac - Compute HMAC in base64 with different algorythms

SYNOPSIS

hmac(key:string, text:string[, algo: integer])

DESCRIPTION

This function compuite HMAC in BASE64.

From Wikipedia:

In cryptography, an HMAC (sometimes disabbreviated as either keyed-hash message authentication code or hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC. Any cryptographic hash function, such as MD5 or SHA-1, may be used in the calculation of an HMAC; the resulting MAC algorithm is termed HMAC-X, where X is the hash function used (e.g. HMAC-MD5 or HMAC-SHA1). The cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function, the size of its hash output, and the size and quality of the key.

PARAMETERS

text
The input strings.
 
key
The value of the key
algo
The algorithm to use. By default, it is set to sha256. The following definition for the algo exist in extenso.sn:
 

%define HMAC_SHA1                   1;

%define HMAC_SHA224                 2;

%define HMAC_SHA256                 0;

%define HMAC_SHA384                 3;

%define HMAC_SHA512                 4

RETURN

Returns the hmac value in base64

EXAMPLES

        hmac(key:"this is a key",data:"this is a test");  return N2QlRcskbAzqng/Zm5k3z6pkDTBqa8q0Zsx8cPPI1dA=
        hmac(algo:0,key:"this is a key",data:"this is a test"); return N2QlRcskbAzqng/Zm5k3z6pkDTBqa8q0Zsx8cPPI1dA=
        hmac(algo:1,key:"this is a key",data:"this is a test"); return FWZky3vay5I0/GKafy/FmJxrvYw= 
        hmac(algo:2,key:"this is a key",data:"this is a test"); return SNDYnrmTQwJtpdzk76+FeLvQXnyYk72Vjo++lA== 
        hmac(algo:3,key:"this is a key",data:"this is a test"); return R8gwP7XxamCLOJuWygRCMxeTAxcHIS/h6HXqu8N0gs4he+fHKU9pamZKnMmXGuLD 
        hmac(algo:4,key:"this is a key",data:"this is a test"); return dR++AXStnCcqRCbLixSVEt/FXP1HtlALj/xHtbVnVFaAshzO0kvjcGcq219wHLxSnzXU+9AMQ06rDopHURcIDQ==
   

AUTHOR

Written by Pierre Laplante