decodePemPrivateKey

fun decodePemPrivateKey(pem: String, password: String? = null): KeyPair(source)

Decode a private key from PEM, PKCS#8, or OpenSSH format.

Supports RSA, ECDSA (nistp256/384/521), and Ed25519 keys in:

  • OpenSSH format (BEGIN OPENSSH PRIVATE KEY)

  • PEM/PKCS#1 RSA (BEGIN RSA PRIVATE KEY)

  • PEM/SEC1 EC (BEGIN EC PRIVATE KEY)

  • PKCS#8 (BEGIN PRIVATE KEY)

Return

JCA KeyPair containing both public and private keys

Parameters

pem

Private key contents as a string

password

Passphrase for encrypted keys, or null if unencrypted

Throws

if the key format is unrecognized or decryption fails