Skip to content

OpenSSHPrivateKeyUtil.encodePrivateKey does not work with ECDSA key pairs #2240

@AlainKnaff

Description

@AlainKnaff

Following code does not work for ECDSA keys (with secp256r1):

        AsymmetricKeyParameter bprv =
            PrivateKeyFactory.createKey(key.getEncoded());
        encodedKey = OpenSSHPrivateKeyUtil.encodePrivateKey(bprv);

It produces a private key which cannot be used neither by openssh, nor by jssh.

However, Topaco's answer to https://stackoverflow.com/questions/79262968/how-to-convert-a-ecprivatekey-to-a-pem-encoded-openssh-format works all right.

OpenSSHPrivateKeyUtil.encodePrivateKey does work fine for Ed25519.

It doesn't work for RSA either, but I'm not sure whether it's supposed to, as RSA is supposed to be packed in a different PEM wrapper (which has -----BEGIN PRIVATE KEY----- instead of -----BEGIN OPENSSH PRIVATE KEY-----).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions