hmac

Compute HMAC

HMAC

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==

SEE ALSO

{{ include("includes/strings.sn") }}

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2018-05-30 laplante@sednove.com

Edit

© 2024 extenso Inc. All rights reserved.