Python HMAC-SHA1 vs Java HMAC-SHA1 different results

纵饮孤独 提交于 2019-11-29 11:11:23
Brendan Long

I think the problem is that in Java, you're using the raw bytes as the key (only converting them to a hex string for output):

System.out.println("Key is..." + bytesToHex(keyBytes) + "\n");
// ...
SecretKeySpec macKey = new SecretKeySpec(keyBytes, "RAW");

But in Python, you're using the hex string:

k = "3132333435363738393031323334353637383930"

It looks like you can decode the hex string with:

raw_key = k.decode('hex')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!