-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
jce1.2fcs
-
generic
-
generic
Name: krT82822 Date: 11/03/99
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
1. Make a HMAC, initialize it with a key of 64 bits, and do a doFinal. The
output is not correct.
2.
You'll have to have a correct implementation of HMAC to test against...
try {
javax.crypto.Mac jceMac = javax.crypto.Mac.getInstance("HmacMD5");
javax.crypto.Mac tedMac = javax.crypto.Mac.getInstance
("HmacMD5", "YourProvider");
javax.crypto.spec.SecretKeySpec key64 = new javax.crypto.spec.SecretKeySpec
("1234567812345678123456781234567812345678123456781234567812345678".getBytes
(), "HmacMD5");
javax.crypto.spec.SecretKeySpec key40 = new javax.crypto.spec.SecretKeySpec
("12345678123456781234567812345678".getBytes(), "HmacMD5");
javax.crypto.spec.SecretKeySpec key65 = new javax.crypto.spec.SecretKeySpec
("12345678123456781234567812345678123456781234567812345678123456781".getBytes
(), "HmacMD5");
byte[] jceBytes, tedBytes;
// init
jceMac.init(key64);
tedMac.init(key64);
jceBytes = jceMac.doFinal("Certicom".getBytes());
tedBytes = tedMac.doFinal("Certicom".getBytes());
if (jceBytes[0] == tedBytes[0])
System.out.println("match");
else System.out.println("fail");
jceMac.init(key63);
tedMac.init(key63);
jceBytes = jceMac.doFinal("Certicom".getBytes());
tedBytes = tedMac.doFinal("Certicom".getBytes());
if (jceBytes[0] == tedBytes[0])
System.out.println("match");
else System.out.println("fail");
jceMac.init(key65);
tedMac.init(key65);
jceBytes = jceMac.doFinal("Certicom".getBytes());
tedBytes = tedMac.doFinal("Certicom".getBytes());
if (jceBytes[0] == tedBytes[0])
System.out.println("match");
else System.out.println("fail");
} catch (Exception e) {
e.printStackTrace();
}
(Review ID: 97436)
======================================================================
- duplicates
-
JDK-4288163 HMAC-MD5 always returns same result, even when initialized with different keys
-
- Resolved
-