Python HMAC-SHA1 vs Java HMAC-SHA1 different results

后端 未结 1 763
你的背包
你的背包 2020-12-19 12:36

I borrowed the HMAC-SHA1 Java code from http://tools.ietf.org/html/rfc6238 and adapted slightly to hardcode it to use one known key/message pair with known output.

I

相关标签:
1条回答
  • 2020-12-19 12:44

    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')
    
    0 讨论(0)
提交回复
热议问题