0
我有一個關鍵:的BigInteger HMAC轉換anomalie
byte: 0011100101010111000101111100101101100010100010111001010010000000
消息:十六進制
byte: 10110001
HMAC輸出:
HMAC-SHA256: ca3871e40207fc0cd66558e4e4fa2817d283da605c15e4c941ff7945ad4be29f
所以,如果我創建一個新的BigInteger(測試)如:
BigInteger test = new BigInteger(hmac);
如果我想要得到的十六進制值回狀:
System.out.println("\noutput: " + test.toString(16));
我得到這個:
output: -35c78e1bfdf803f3299aa71b1b05d7e82d7c259fa3ea1b36be0086ba52b41d61
問題出在哪裏?或者我該如何計算消息中的hmac-sha256,並從頭開始使用BigInteger。
key,message和hmac是字節數組。
如果我嘗試將字節「11010100」轉換爲BigInteger,它將轉換爲負值「-101100」 爲什麼BigInteger將其轉換爲負值?第一位是符號位,你怎麼禁用符號位?
什麼是你'hmac'變量的確切價值? – jlordo
ca3871e40207fc0cd66558e4e4fa2817d283da605c15e4c941ff7945ad4be29f – x4k3p
我不能重現你的問題,因爲你發佈的代碼拋出一個'NumberFormatException' ... – jlordo