-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
8u201, 11-pool, 17-pool
javax.crypto.EncryptedPrivateKeyInfo does not recognize PBEWithHmacSHA256AndAES_128 and PBEWithHmacSHA256AndAES_256 although the documentation @
https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#AlgorithmParameters sees to indicate it should. This error is also observed with JDK 11.
import javax.crypto.*;
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.*;
import javax.crypto.spec.*;
public class Test {
public static void main(String[] args) throws Exception {
byte[] salt = new byte[]{0, 17, 34, 51, 68, 85, 102, 119};
char[] pwd = new char[] {'p','a','s','s','w','o','r','d'};
//AlgorithmParameters ap =
AlgorithmParameters.getInstance("PBEWithHmacSHA256AndAES_256");
AlgorithmParameters ap =
AlgorithmParameters.getInstance("PBEWithHmacSHA256AndAES_128");
PBEParameterSpec spec = new PBEParameterSpec(salt, 5);
ap.init(spec);
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
//Cipher ciph = Cipher.getInstance("PBEWithHmacSHA256AndAES_256");
Cipher ciph = Cipher.getInstance("PBEWithHmacSHA256AndAES_128");
SecretKey sk = SecretKeyFactory.getInstance(
ap.getAlgorithm()).generateSecret(new PBEKeySpec(pwd, spec.getSalt(), spec.getIterationCount()));
ciph.init(Cipher.ENCRYPT_MODE, sk, spec);
byte[] result = ciph.doFinal(privateKey.getEncoded());
EncryptedPrivateKeyInfo epk = new EncryptedPrivateKeyInfo(ap, result);
}
}
https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#AlgorithmParameters sees to indicate it should. This error is also observed with JDK 11.
import javax.crypto.*;
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.*;
import javax.crypto.spec.*;
public class Test {
public static void main(String[] args) throws Exception {
byte[] salt = new byte[]{0, 17, 34, 51, 68, 85, 102, 119};
char[] pwd = new char[] {'p','a','s','s','w','o','r','d'};
//AlgorithmParameters ap =
AlgorithmParameters.getInstance("PBEWithHmacSHA256AndAES_256");
AlgorithmParameters ap =
AlgorithmParameters.getInstance("PBEWithHmacSHA256AndAES_128");
PBEParameterSpec spec = new PBEParameterSpec(salt, 5);
ap.init(spec);
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
//Cipher ciph = Cipher.getInstance("PBEWithHmacSHA256AndAES_256");
Cipher ciph = Cipher.getInstance("PBEWithHmacSHA256AndAES_128");
SecretKey sk = SecretKeyFactory.getInstance(
ap.getAlgorithm()).generateSecret(new PBEKeySpec(pwd, spec.getSalt(), spec.getIterationCount()));
ciph.init(Cipher.ENCRYPT_MODE, sk, spec);
byte[] result = ciph.doFinal(privateKey.getEncoded());
EncryptedPrivateKeyInfo epk = new EncryptedPrivateKeyInfo(ap, result);
}
}
- duplicates
-
JDK-8298420 Implement PEM Encodings of Cryptographic Objects (Preview)
- In Progress