Qore Programming Language Reference Manual  0.8.11.1
HMAC Functions

Functions

string Qore::DSS1_hmac (data data, string key)
 Returns the DSS1 (SHA-1 and DSA) based HMAC of the supplied argument as a hex string. More...
 
string Qore::DSS_hmac (data data, string key)
 Returns the DSS (SHA-0 and DSA) based HMAC of the supplied argument as a hex string. More...
 
string Qore::MD2_hmac (data data, string key)
 Returns the MD2 based HMAC of the supplied argument as a hex string. More...
 
string Qore::MD4_hmac (data data, string key)
 Returns the MD4 based HMAC of the supplied argument as a hex string. More...
 
string Qore::MD5_hmac (data data, string key)
 Returns the MD5 based HMAC of the supplied argument as a hex string. More...
 
string Qore::MDC2_hmac (data data, string key)
 Returns the MDC2 based HMAC of the supplied argument as a hex string. More...
 
string Qore::RIPEMD160_hmac (data data, string key)
 Returns the RIPEMD based HMAC of the supplied argument as a hex string. More...
 
string Qore::SHA1_hmac (data data, string key)
 Returns the SHA1 based HMAC of the supplied argument as a hex string. More...
 
string Qore::SHA224_hmac (data data, string key)
 Returns the SHA224 based HMAC of the supplied argument as a hex string. More...
 
string Qore::SHA256_hmac (data data, string key)
 Returns the SHA256 based HMAC of the supplied argument as a hex string. More...
 
string Qore::SHA384_hmac (data data, string key)
 Returns the SHA384 based HMAC of the supplied argument as a hex string. More...
 
string Qore::SHA512_hmac (data data, string key)
 Returns the SHA512 based HMAC of the supplied argument as a hex string. More...
 
string Qore::SHA_hmac (data data, string key)
 Returns the SHA based HMAC of the supplied argument as a hex string. More...
 

Detailed Description

Qore's cryptography support is provided by the OpenSSL library.

In cryptography, a keyed-hash message authentication code (HMAC) is a specific construction for calculating a message authentication code (MAC) involving a cryptographic hash function in combination with a secret cryptographic key. As with any MAC, it may be used to simultaneously verify both the data integrity and the authentication of a message. 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-MD5 or HMAC-SHA1 accordingly. The cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function, the size of its hash output, and on the size and quality of the key.

For more info: Wikipedia's Hash-based message authentication code article.

See also:

Function Documentation

string Qore::DSS1_hmac ( data  data,
string  key 
)

Returns the DSS1 (SHA-1 and DSA) based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "37a3cc73159aa129b0eb22bbdf4b9309d389f629")
Example:
my string $str = DSS1_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "37a3cc73159aa129b0eb22bbdf4b9309d389f629"
Note
this algorithm is considered outdated and is included for backwards-compatibility
Exceptions
DSS1-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::DSS_hmac ( data  data,
string  key 
)

Returns the DSS (SHA-0 and DSA) based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "37a3cc73159aa129b0eb22bbdf4b9309d389f629")
Example:
my string $str = DSS_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "37a3cc73159aa129b0eb22bbdf4b9309d389f629"
Note
this algorithm is considered outdated and is included for backwards-compatibility
Exceptions
DSS-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::MD2_hmac ( data  data,
string  key 
)

Returns the MD2 based HMAC of the supplied argument as a hex string.

Platform Availability:
Qore::Option::HAVE_MD2
Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "27f5f17500b408e97643403ea8ef1413")
Example:
my string $str = MD2_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "27f5f17500b408e97643403ea8ef1413"
Exceptions
MD2-HMAC-ERRORerror calculating digest (should not normally happen)
See also
MD2_bin()
string Qore::MD4_hmac ( data  data,
string  key 
)

Returns the MD4 based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "053d084f321a3886e60166ebd9609ce1")
Example:
my string $str = MD4_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "053d084f321a3886e60166ebd9609ce1"
Exceptions
MD4-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::MD5_hmac ( data  data,
string  key 
)

Returns the MD5 based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "87505c6164aaf6ca6315233902a01ef4")
Example:
my string $str = MD5_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "87505c6164aaf6ca6315233902a01ef4"
Note
the MD5 algorithm is not collision-resistant; it's recommended to use another hash algorithm (like SHA-256) if cryptographic security is important
Exceptions
MD5-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::MDC2_hmac ( data  data,
string  key 
)

Returns the MDC2 based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "e0ef6a6803e58807c5db395e180a999c")
Example:
my string $str = MDC2_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "e0ef6a6803e58807c5db395e180a999c"
Exceptions
MDC2-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::RIPEMD160_hmac ( data  data,
string  key 
)

Returns the RIPEMD based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "4bca70bca1601aba57624eeb2606535cb12f2079")
Example:
my string $str = RIPEMD160_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "4bca70bca1601aba57624eeb2606535cb12f2079"
Exceptions
RIPEMD160-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::SHA1_hmac ( data  data,
string  key 
)

Returns the SHA1 based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "37a3cc73159aa129b0eb22bbdf4b9309d389f629")
Example:
my string $str = SHA1_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "37a3cc73159aa129b0eb22bbdf4b9309d389f629"
Note
Cryptographic weaknesses were discovered in SHA-1, and the standard was no longer approved for most cryptographic uses after 2010.
Exceptions
SHA1-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::SHA224_hmac ( data  data,
string  key 
)

Returns the SHA224 based HMAC of the supplied argument as a hex string.

Platform Availability:
Qore::Option::HAVE_SHA224
Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "fad5667fa5aa412044555b7e077fced62372fe9c6ce20815609da12c")
Example:
my string $str = SHA224_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "fad5667fa5aa412044555b7e077fced62372fe9c6ce20815609da12c"
Exceptions
SHA224-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::SHA256_hmac ( data  data,
string  key 
)

Returns the SHA256 based HMAC of the supplied argument as a hex string.

Platform Availability:
Qore::Option::HAVE_SHA256
Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "1c90c21e227712b62019ff831f34cba22c2e70f1a902651ef69a70705ee0f754")
Example:
my string $str = SHA256_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "1c90c21e227712b62019ff831f34cba22c2e70f1a902651ef69a70705ee0f754"
Exceptions
SHA256-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::SHA384_hmac ( data  data,
string  key 
)

Returns the SHA384 based HMAC of the supplied argument as a hex string.

Platform Availability:
Qore::Option::HAVE_SHA384
Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "e2c253c6dcb050990b4da3cee95cd7b227f43388fa8116f476f59395af295d0d3bb7156ab2fcd0663b0500249a7a0865")
Example:
my string $str = SHA384_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "e2c253c6dcb050990b4da3cee95cd7b227f43388fa8116f476f59395af295d0d3bb7156ab2fcd0663b0500249a7a0865"
Exceptions
SHA384-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::SHA512_hmac ( data  data,
string  key 
)

Returns the SHA512 based HMAC of the supplied argument as a hex string.

Platform Availability:
Qore::Option::HAVE_SHA512
Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "8dcefd7ea3f90ff1c822b5e9547fc36edf78c3e4ce13d47510a212a406bdda1a4094e7ea5ade90e1c736e204d331a814520eba49f3d074e2c261208de07264f6")
Example:
my string $str = SHA512_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "8dcefd7ea3f90ff1c822b5e9547fc36edf78c3e4ce13d47510a212a406bdda1a4094e7ea5ade90e1c736e204d331a814520eba49f3d074e2c261208de07264f6"
Exceptions
SHA512-HMAC-ERRORerror calculating digest (should not normally happen)
string Qore::SHA_hmac ( data  data,
string  key 
)

Returns the SHA based HMAC of the supplied argument as a hex string.

Parameters
datathe data to process and produce a digest for; the trailing null character is not included in the digest when processing string arguments
keya secret passphrase/key
Returns
a hex string of the digest (ex: "0ad47c8d36dc4606d52f7e4cbd144ef2fda492a0")
Example:
my string $str = SHA_hmac("Hello There This is a Test - 1234567890", "a key");
# returns "0ad47c8d36dc4606d52f7e4cbd144ef2fda492a0"
Note
SHA/SHA0 was withdrawn shortly after publication due to an undisclosed "significant flaw" and replaced by the slightly revised version SHA-1.
Exceptions
SHA-HMAC-ERRORerror calculating digest (should not normally happen)