Di tutorial ini kita belajar membuat enkripsi Symmetric Signature HMAC SHA512 menggunakan Python.
Beberapa library yang kita pakai diantaranya haslib, hmac dan base64.
import hashlib
import hmac
import base64
secretKey = "bulan-purnama-dikota-malang"
message = "test symmetric encryption"
hmac_digest = hmac.new(
key= bytes(secretKey, 'utf-8'),
msg= bytes(message, 'utf-8'),
digestmod= hashlib.sha512
).digest()
ubah ke base64 encode:
base64.b64encode(hmac_digest).decode()
hmac_digest = hmac.new(
key= bytes(secretKey, 'utf-8'),
msg= bytes(message, 'utf-8'),
digestmod= hashlib.sha512
).digest()
compare dengan compare_digest()
hmac.compare_digest(hmac_digest, base64.b64decode(signature))