Thursday 29 December 2016

What is hmac?

Keyed-Hash Message Authentication Code( hmac module)

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.

HMAC-SHA1 and HMAC-MD5 are used within the IPsec and TLS protocols.

Example:
import hmac
digest_maker = hmac.new(b'secret-shared-key-goes-here')
f = open('D:\\configuration.txt', 'rb')
try:
    while True:
        block = f.read(1024)
        if not block:
            break
        digest_maker.update(block)
finally:
    f.close()
digest = digest_maker.hexdigest()
print(digest)

Output: 8d0cc23dbc570e65c5bf2b5cdc72aae3