python hexdigest,Java方法,可以为Hex中的HMAC-SHA256提供与Python方法相同的输出
你確定你的密鑰和輸入是相同的,并在java和python中正確編碼?
HMAC-SHA256在兩個(gè)平臺(tái)上的工作方式相同.
Java的
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec("1234".getBytes(), "HmacSHA256");
sha256_HMAC.init(secretKey);
byte[] hash = sha256_HMAC.doFinal("test".getBytes());
String check = Hex.encodeHexString(hash);
System.out.println(new String(check));
Output
24c4f0295e1bea74f9a5cb5bc40525c8889d11c78c4255808be00defe666671f
Python
print hmac.new("1234", "test", hashlib.sha256).hexdigest();
Output
24c4f0295e1bea74f9a5cb5bc40525c8889d11c78c4255808be00defe666671f
總結(jié)
以上是生活随笔為你收集整理的python hexdigest,Java方法,可以为Hex中的HMAC-SHA256提供与Python方法相同的输出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手机钉钉回收站在哪里
- 下一篇: 钉钉极速打卡怎么关闭