0

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");
rrk
  • 15,677
  • 4
  • 29
  • 45
Vlado
  • 1
  • Is this the same question? https://stackoverflow.com/questions/53879309/coldfusion-equivalent-of-php-openssl-sign – CFMLBread Dec 01 '22 at 21:57
  • Not really. It is very similiar question though. But in my case I have ecnrypted privated key with password. PrivateKeyInfo privateKeyInfo = keyInfo.decryptPrivateKeyInfo(pkcs8Prov); – Vlado Dec 04 '22 at 15:37

0 Answers0