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)

  • ML-DSA-44/Ed25519 composite keys in OpenSSH or PKCS#8 format

  • Pure ML-DSA keys in PKCS#8 format

ML-DSA requires a capable installed provider. PKCS#8 must include the public key (RFC 5958), or be followed by a matching BEGIN PUBLIC KEY PEM block.

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