Interop: HmacSHA1 in Java and dotNet
Posted
by wilth
on Stack Overflow
See other posts from Stack Overflow
or by wilth
Published on 2010-04-19T07:13:56Z
Indexed on
2010/04/19
7:23 UTC
Read the original article
Hit count: 321
Hello,
In an app we are calculating a SHA1Hmac in java using the following:
SecretKey key = new SecretKeySpec(secret, "HmacSHA1");
Mac m = Mac.getInstance("HmacSHA1");
m.init(secret);
byte[] hmac = m.doFinal(data);
And later, the hmac is verified in C# - on a SmartCard - using:
HMACSHA1 hmacSha = new HMACSHA1(secret);
hmacSha.Initialize();
byte[] hmac = hmacSha.ComputeHash(data);
However, the result is not the same. Did I overlook something important?
The inputs seem to be the same. Here some sample inputs:
Data: 546573746461746131323341fa3c35
Key: 6d795472616e73616374696f6e536563726574
Result Java: 37dbde318b5e88acbd846775e38b08fe4d15dac6
Result C#: dd626b0be6ae78b09352a0e39f4d0e30bb3f8eb9
I wouldn't mind to implement my own hmacsha1 on both platforms, but using what already exists....
Thanks!
© Stack Overflow or respective owner