Hi Chris,
In my understanding you are trying to get the HMAC signature of a message using MATLAB and are trying to do the same with python. However, the output of both the code is not identical.
Upon reviewing both codes, I noticed that hashing for the message is absent in the Python code. To address this, I have added the necessary hashing for the message using 'hashlib' on lines 8-10 in the Python code as shown below:
import hashlib
import base64
import hmac
secret = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
msg = '123'
hash256_class = hashlib.sha256()
challenge_hash = hash256_class.update(msg.encode())
challenge_hash = hash256_class.digest()
secret_uint8 = base64.b64decode(secret)
signature = hmac.new(secret_uint8, challenge_hash, hashlib.sha256)
signature_b64 = base64.b64encode(signature.digest()).decode('utf-8')
print(signature_b64)
#Output: uFpcDGx9zh1PBhdfDed+HaJjnfX7PxRt24weAj8DO8w=
Please refer to the following Python documentation link for more information on ‘hashlib’:
Hope this helps!