Class OpenSSHPrivateKeyUtil
java.lang.Object
org.bouncycastle.crypto.util.OpenSSHPrivateKeyUtil
A collection of utility methods for parsing OpenSSH private keys.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Encode a cipher parameters into an OpenSSH private key.static AsymmetricKeyParameterparsePrivateKeyBlob(byte[] blob) Parse a private key.static AsymmetricKeyParameterparsePrivateKeyBlob(byte[] blob, byte[] passphrase) Parse a private key, decrypting it with the supplied passphrase if it is a passphrase-protectedopenssh-key-v1key.
-
Method Details
-
encodePrivateKey
Encode a cipher parameters into an OpenSSH private key. This does not add headers like ----BEGIN RSA PRIVATE KEY----- Parameters:
params- the cipher parameters.- Returns:
- a byte array
- Throws:
IOException
-
parsePrivateKeyBlob
Parse a private key.This method accepts the body of the OpenSSH private key. The easiest way to extract the body is to use PemReader, for example:
byte[] blob = new PemReader([reader]).readPemObject().getContent(); CipherParameters params = parsePrivateKeyBlob(blob);
- Parameters:
blob- The key.- Returns:
- A cipher parameters instance.
-
parsePrivateKeyBlob
Parse a private key, decrypting it with the supplied passphrase if it is a passphrase-protectedopenssh-key-v1key.This method accepts the body of the OpenSSH private key (see
parsePrivateKeyBlob(byte[])for how to extract it from PEM). For an unencrypted keypassphraseis ignored and may benull; for an encrypted key it must carry the passphrase bytes (the OpenSSH client uses the raw UTF-8 bytes). ThebcryptKDF and the OpenSSH cipher suite (aes128/192/256-ctr, aes128/192/256-cbc, 3des-cbc, aes128/256-gcm@openssh.com and chacha20-poly1305@openssh.com) are supported.- Parameters:
blob- The key.passphrase- The passphrase bytes, ornullfor an unencrypted key. The array is not modified; the caller is responsible for clearing it.- Returns:
- A cipher parameters instance.
-