2

Is it possible to write these functions in Python?

var hash = CryptoJS.HmacSHA256("Message", "Secret Passphrase");
var v = hash.toString(CryptoJS.enc.Hex)

Thanks in advance.

1 Answer 1

5

Yes, using hmac and hashlib from the standard library.

import hashlib
import hmac

message = b"Message"
key = b"Secret Passphrase"

h = hmac.new(key, message, hashlib.sha256)
print(h.hexdigest())

Gives output 32c647602ab4c4c7543e9c50ae25e567c3354e1532b11649ce308e6e2568d205, which is identical to v in answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.