I'm trying to retrieve a private key, using the Bouncy Castle, Ktor and Kotlin.
fun readPrivateKey(filePath: String): Result<RSAPrivateKey> = runCatching {
val pemParse = PEMParser(FileReader(filePath))
val privateKey = PrivateKeyInfo.getInstance(pemParse.readObject())
JcaPEMKeyConverter().getPrivateKey(privateKey) as RSAPrivateKey
}.onFailure { throw it }
but when testing the function, I get the following error
unknown object in getInstance: org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo java.lang.IllegalArgumentException: unknown object in getInstance: org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo
the error occurs in this line: privateKey = PrivateKeyInfo.getInstance(pemParse.readObject())
I generated my private key with the following code:
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -aes-256-cbc -out development_erp_private.key
what am I doing wrong?