2

I need help finding out how I can decode a base64 encoded HMAC-SHA256 hash with python.

From an API I'm given a base64 encoded HMAC-SHA256 hash of a secret key.

The message I get from the API is: "Mw2aXjiDQABoNi5jB09ie8iTkET4t6JiQJSh+/jIceY="

My secret is: "testapp"

Using the answer from this post Calculating a SHA hash with a string + secret key in python

import hmac
import hashlib
import base64
dig = hmac.new(b'testapp', msg=b'Mw2aXjiDQABoNi5jB09ie8iTkET4t6JiQJSh+/jIceY=, digestmod=hashlib.sha256).digest()
base64.b64encode(dig).decode()

I get "WTEb7ZIAPb89b0NV8NnI9+0x5alkng1LZ7Ffz39bveE="

I expected a response equal to my message. What am I doing wrong here ?

Any help is appreciated. Best regards Kresten

Kresten
  • 810
  • 13
  • 36
  • 5
    Why do you expect to get `Mw2aXjiDQABoNi5...`? You can't "decode" a hash for the same reason you can't extract 5 + 5 given 10. Hashing loses information. – Blender Apr 24 '18 at 20:17

0 Answers0