python base64 to hex

Since two weeks, I’m trying and reading to solve this problem, but everything I tried didn’t worked 🙁

I’m using python 2.7.

I do have, as far as I understand, a base64-string from the format: AAMkADk0ZjU4ODc1LTY1MzAtNDdhZS04NGU5LTAwYjE2Mzg5NDA1ZABGAAAAAAAZS9Y2rt6uTJgnyUZSiNf0BwC6iam6EuExS4FgbbOF87exAAAAdGVuAAC6iam6EuExS4FgbbOF87exAAAxj5dhAAA=

I want to convert it to a hex-string. Which should result in 00000000194BD636AEDEAE4C9827C9465288D7F40700BA89A9BA12E1314B81606DB385F3B7B100000074656E0000BA89A9BA12E1314B81606DB385F3B7B10000318F97610000

I tried it with the following code:

def itemid_to_entryid(itemid):
    decoded_val = base64.b64decode(itemid)
    decoded_val = ''.join( ["%02X" % ord(x) for x in decoded_val ] ).strip()
    decoded_val = decoded_val.upper()
    return decoded_val


itemid = 'AAMkADk0ZjU4ODc1LTY1MzAtNDdhZS04NGU5LTAwYjE2Mzg5NDA1ZABGAAAAAAAZS9Y2rt6uTJgnyUZSiNf0BwC6iam6EuExS4FgbbOF87exAAAAdGVuAAC6iam6EuExS4FgbbOF87exAAAxj5dhAAA='

entryid = itemid_to_entryid(itemid)
print(entryid)

which always returns me the following: 0003240039346635383837352D363533302D343761652D383465392D30306231363338393430356400460000000000194BD636AEDEAE4C9827C9465288D7F40700BA89A9BA12E1314B81606DB385F3B7B100000074656E0000BA89A9BA12E1314B81606DB385F3B7B10000318F97610000

and I really don’t get, what I’m doing wrong and really would appreciate any help in understanding what I’m doing wrong.

Kind regards Ben

Leave a Comment