Skip to content
Advertisement

How read a PKCS8 encrypted Private key which is also encoded in DER with bouncycastle?

I have tried answers of these questions:

Bouncy Castle : PEMReader => PEMParser

Read an encrypted private key with bouncycastle/spongycastle

However as my encrypted key is encoded in DER when I call

JavaScript

object is null.

I can convert it to PEM with this openssl’s command (it decrypts the key too)

JavaScript

but I need to read the key in its original file

Advertisement

Answer

Both those Qs are about parsing, and decrypting, files using OpenSSL’s ‘legacy PEM’ encryption. You are using PKCS8 encryption which is different though similar, so Reading PKCS8 in PEM format: Cannot find provider is closer. You can use most of the approach there, but skipping the PEM parse:

JavaScript
Advertisement