Bouncy Castle Cryptography Library 1.85

org.bouncycastle.jcajce.spec
Class OpenSSHPrivateKeySpec

java.lang.Object
  extended byjava.security.spec.EncodedKeySpec
      extended byorg.bouncycastle.jcajce.spec.OpenSSHPrivateKeySpec
All Implemented Interfaces:
java.security.spec.KeySpec

public class OpenSSHPrivateKeySpec
extends java.security.spec.EncodedKeySpec

OpenSSHPrivateKeySpec holds and encoded OpenSSH private key. The format of the key can be either ASN.1 or OpenSSH.


Constructor Summary
OpenSSHPrivateKeySpec(byte[] encodedKey)
          Accept an encoded key and determine the format.
OpenSSHPrivateKeySpec(byte[] encodedKey, char[] password)
          Accept an encoded key, determine the format, and carry the passphrase used to decrypt a passphrase-protected openssh-key-v1 key.
 
Method Summary
 java.lang.String getFormat()
          Return the format, either OpenSSH for the OpenSSH propriety format or ASN.1.
 char[] getPassword()
          Return the passphrase used to decrypt an encrypted openssh-key-v1 key, or if none was supplied.
 
Methods inherited from class java.security.spec.EncodedKeySpec
getEncoded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenSSHPrivateKeySpec

public OpenSSHPrivateKeySpec(byte[] encodedKey)
Accept an encoded key and determine the format.

The encoded key should be the Base64 decoded blob between the "---BEGIN and ---END" markers. This constructor will endeavour to find the OpenSSH format magic value. If it can not then it will default to ASN.1. It does not attempt to validate the ASN.1

Example: OpenSSHPrivateKeySpec privSpec = new OpenSSHPrivateKeySpec(rawPriv);

KeyFactory kpf = KeyFactory.getInstance("RSA", "BC"); PrivateKey prk = kpf.generatePrivate(privSpec);

OpenSSHPrivateKeySpec rcPrivateSpec = kpf.getKeySpec(prk, OpenSSHPrivateKeySpec.class);

Parameters:
encodedKey - The encoded key.

OpenSSHPrivateKeySpec

public OpenSSHPrivateKeySpec(byte[] encodedKey,
                             char[] password)
Accept an encoded key, determine the format, and carry the passphrase used to decrypt a passphrase-protected openssh-key-v1 key.

Only the openssh-key-v1 format supports encryption; for an unencrypted key (or the ASN.1 format) the password is ignored and may be . The password characters are used as their UTF-8 bytes, matching the OpenSSH client.

Parameters:
encodedKey - The encoded key.
password - The passphrase, or for an unencrypted key.
Method Detail

getFormat

public java.lang.String getFormat()
Return the format, either OpenSSH for the OpenSSH propriety format or ASN.1.

Returns:
the format OpenSSH or ASN.1

getPassword

public char[] getPassword()
Return the passphrase used to decrypt an encrypted openssh-key-v1 key, or if none was supplied.

Returns:
the passphrase, or .

Bouncy Castle Cryptography Library 1.85