I'm trying to convert openSSL to Coldfusion using encrypted PEM key with password.
JAVA CODE:
String privateKeyFile = "test_key.pem";
FileInputStream privateKey = null;
EMParser pemRd = new PEMParser(new InputStreamReader(privateKey));
Object objectInPemFile = pemRd.readObject();
PKCS8EncryptedPrivateKeyInfo keyInfo = (PKCS8EncryptedPrivateKeyInfo) objectInPemFile;
String pwd = "secret";
InputDecryptorProvider pkcs8Prov = new JceOpenSSLPKCS8DecryptorProviderBuilder().build(pwd.toCharArray());
PrivateKeyInfo privateKeyInfo = keyInfo.decryptPrivateKeyInfo(pkcs8Prov);
This is part I can't manage to convert to Coldfusion:
PrivateKeyInfo privateKeyInfo = keyInfo.decryptPrivateKeyInfo(pkcs8Prov);
So far I got this Coldfusion code, but the last part (getting the key) is not working:
COLDFUSION CODE
privateKeyFile = createObject("java", "java.io.FileReader").init(ExpandPath("test_key.pem") );
privateKey = createObject("java", "org.bouncycastle.openssl.PEMParser").init( privateKeyFile ).readPemObject().getContent();
privateKey= toBase64(privateKey);
privateKeyFile.close();
privateKey = privateKey.replaceAll("^-+BEGIN RSA PRIVATE KEY-+", "");
privateKey = privateKey.replaceAll("-+END RSA PRIVATE KEY-+", "");
privateKey = privateKey.replaceAll(chr(10), "").trim();
decryptorProvider = createObject("java", "org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder").build('secret');
decryptedKeyPair = createObject("java","org.bouncycastle.openssl.PEMEncryptedKeyPair");