Skip to content

How to convert an ECPrivateKey to a PEM-encoded OPENSSH PRIVATE KEY? #1935

Closed Answered by cowwoc
cowwoc asked this question in Q&A
Discussion options

You must be logged in to vote

It doesn't look like BouncyCastle can do this, but the following works with the MINA sshd library (https://github.com/apache/mina-sshd):

/**
 * Writes a {@code KeyPair} as a PEM-encoded OpenSSH format stream.
 *
 * @param keys a key pair
 * @param out  the stream to write into
 * @throws NullPointerException     if any of the arguments are null
 * @throws IOException              if an error occurs while reading the stream
 * @throws GeneralSecurityException if the key pair is unsupported or invalid
 */
public void writeKeyPairAsOpenSsh(Collection<KeyPair> keys, OutputStream out)
	throws IOException, GeneralSecurityException
{
	OpenSSHKeyPairResourceWriter openSshWriter = OpenSSHKeyPairRe…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cowwoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant