-
Bug
-
Resolution: Fixed
-
P5
-
unknown
-
hopper
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2109774 | jce1.2.2beta | Valerie Peng | P5 | Resolved | Fixed | jce1.2.2beta |
The following test demonstrates that the wrong exception is
being thrown for an invalid wrappedKeyType during Cipher.unwrap():
Test a) and test b) differ only in the wrappedKeyType. a) is erroneously
set to PUBLIC_KEY and b) is correctly set to SECRET_KEY. Test a throws a
NoSuchAlgorithmException instead of an InvalidKeyException
per the spec.
The output of the test is:
Test #1java.security.NoSuchAlgorithmException:
No installed providers can create keys for the Blowfishalgorithm
Test b completes without error.
------------------------------------------------------------------------
import java.security.*;
import javax.crypto.*;
public class testWrap2 {
public static void main (String[] args) {
try {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Cipher cp = Cipher.getInstance("Blowfish","SunJCE");
//
KeyGenerator kg = KeyGenerator.getInstance("Blowfish");
Key mykey = kg.generateKey();
AlgorithmParameters params = cp.getParameters();
cp.init(Cipher.WRAP_MODE,mykey,params);
byte[] b_b = cp.wrap(mykey);
cp.init(Cipher.UNWRAP_MODE,mykey,params);
Key mykey2 = cp.unwrap(b_b,"Blowfish",Cipher.PUBLIC_KEY);
} catch (Exception e) {
System.out.println("Test a)" + e);
}
try {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Cipher cp = Cipher.getInstance("Blowfish","SunJCE");
//
KeyGenerator kg = KeyGenerator.getInstance("Blowfish");
Key mykey = kg.generateKey();
AlgorithmParameters params = cp.getParameters();
cp.init(Cipher.WRAP_MODE,mykey,params);
byte[] b_b = cp.wrap(mykey);
cp.init(Cipher.UNWRAP_MODE,mykey,params);
Key mykey2 = cp.unwrap(b_b,"Blowfish",Cipher.SECRET_KEY);
} catch (Exception e) {
System.out.println("Test b)" + e);
}
System.out.println("Exit without problem");
System.exit(0);
}
}
being thrown for an invalid wrappedKeyType during Cipher.unwrap():
Test a) and test b) differ only in the wrappedKeyType. a) is erroneously
set to PUBLIC_KEY and b) is correctly set to SECRET_KEY. Test a throws a
NoSuchAlgorithmException instead of an InvalidKeyException
per the spec.
The output of the test is:
Test #1java.security.NoSuchAlgorithmException:
No installed providers can create keys for the Blowfishalgorithm
Test b completes without error.
------------------------------------------------------------------------
import java.security.*;
import javax.crypto.*;
public class testWrap2 {
public static void main (String[] args) {
try {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Cipher cp = Cipher.getInstance("Blowfish","SunJCE");
//
KeyGenerator kg = KeyGenerator.getInstance("Blowfish");
Key mykey = kg.generateKey();
AlgorithmParameters params = cp.getParameters();
cp.init(Cipher.WRAP_MODE,mykey,params);
byte[] b_b = cp.wrap(mykey);
cp.init(Cipher.UNWRAP_MODE,mykey,params);
Key mykey2 = cp.unwrap(b_b,"Blowfish",Cipher.PUBLIC_KEY);
} catch (Exception e) {
System.out.println("Test a)" + e);
}
try {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
Cipher cp = Cipher.getInstance("Blowfish","SunJCE");
//
KeyGenerator kg = KeyGenerator.getInstance("Blowfish");
Key mykey = kg.generateKey();
AlgorithmParameters params = cp.getParameters();
cp.init(Cipher.WRAP_MODE,mykey,params);
byte[] b_b = cp.wrap(mykey);
cp.init(Cipher.UNWRAP_MODE,mykey,params);
Key mykey2 = cp.unwrap(b_b,"Blowfish",Cipher.SECRET_KEY);
} catch (Exception e) {
System.out.println("Test b)" + e);
}
System.out.println("Exit without problem");
System.exit(0);
}
}
- backported by
-
JDK-2109774 Wrong exception thrown for invalid key type in Cipher.unwrap
-
- Resolved
-