def hmac_signature(string, shared_secret, challenge_hmac):
    if six.PY3:
        msg = salt.utils.to_bytes(string)
        key = salt.utils.to_bytes(shared_secret)
        challenge = salt.utils.to_bytes(challenge_hmac)
    else:
        msg = string
        key = shared_secret
        challenge = challenge_hmac
    hmac_hash = hmac.new(key, msg, hashlib.sha256)
    valid_hmac = base64.b64encode(hmac_hash.digest())
    return valid_hmac == challenge
Verify a challenging hmac signature against a string / shared-secret
dataset/ETHPy150Open saltstack/salt/salt/modules/hashutil.py/hmac_signature