sumit
sumit

Reputation: 15464

hashlib.sha256 returned some weird characters in python

In javascript the code below returned

eec097af19ad461ac825ccce57a012543da33c986e4607475e1fe5c6dc098d0a

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.1/build/rollups/hmac-sha512.js"></script>
<script>
   var hash = CryptoJS.HmacSHA256("Message", "Secret");
</script>

In python same logic returned some weird characters like �����F�%��W�T=�<�nFG^��� �

import hmac
import hashlib
import base64
hash = hmac.new('Secret', "Message", hashlib.sha256).digest()

I think they should return same hash as i have used same algorithm for both. Any suggestions ? Thanks

Upvotes: 0

Views: 836

Answers (1)

Maksym Polshcha
Maksym Polshcha

Reputation: 18358

try hexdigest()

import hmac
import hashlib
import base64
hash = hmac.new('Secret', "Message", hashlib.sha256).hexdigest()

Upvotes: 3

Related Questions