use of org.bouncycastle.pkcs.jcajce.JcePKCSPBEInputDecryptorProviderBuilder in project candlepin by candlepin.
the class PrivateKeyReaderTest method testReadEncryptedPKCS8.
/**
* Currently fails due to a bug in OpenJDK: https://bugs.openjdk.java.net/browse/JDK-8076999
*/
@Test
@Ignore
public void testReadEncryptedPKCS8() throws Exception {
String keyFile = "keys/pkcs8-aes256-encrypted.pem";
try (InputStream keyStream = cl.getResourceAsStream(keyFile);
Reader expectedReader = new InputStreamReader(cl.getResourceAsStream(keyFile))) {
PrivateKey actualKey = new PrivateKeyReader().read(keyStream, "password");
PKCS8EncryptedPrivateKeyInfo expected = (PKCS8EncryptedPrivateKeyInfo) new PEMParser(expectedReader).readObject();
// the PBE in JcePKCSPBEInputDecryptorProviderBuilder stands for "password based encryption"
InputDecryptorProvider provider = new JcePKCSPBEInputDecryptorProviderBuilder().setProvider(BC_PROVIDER).build(PASSWORD);
PrivateKeyInfo decryptedInfo = expected.decryptPrivateKeyInfo(provider);
PrivateKey expectedKey = new JcaPEMKeyConverter().setProvider(BC_PROVIDER).getPrivateKey(decryptedInfo);
assertEquals(actualKey, expectedKey);
}
}
Aggregations