Top Description Fields Constructors Methods
org.bouncycastle.crypto.util

public Class OpenSSHPrivateKeyUtil

extends Object
Class Inheritance
Imports
java.io.IOException, java.math.BigInteger, org.bouncycastle.asn1.ASN1EncodableVector, .ASN1Integer, .ASN1ObjectIdentifier, .ASN1Sequence, .ASN1TaggedObject, .DERSequence, org.bouncycastle.asn1.nist.NISTNamedCurves, org.bouncycastle.asn1.pkcs.PrivateKeyInfo, .RSAPrivateKey, org.bouncycastle.asn1.sec.ECPrivateKey, org.bouncycastle.asn1.x9.ECNamedCurveTable, .X9ECParameters, org.bouncycastle.crypto.CryptoServicesRegistrar, org.bouncycastle.crypto.params.AsymmetricKeyParameter, .DSAParameters, .DSAPrivateKeyParameters, .ECNamedDomainParameters, .ECPrivateKeyParameters, .Ed25519PrivateKeyParameters, .Ed25519PublicKeyParameters, .RSAPrivateCrtKeyParameters, org.bouncycastle.util.Arrays, .BigIntegers, .Strings

A collection of utility methods for parsing OpenSSH private keys.

Field Summary

Modifier and TypeField and Description
pack-priv static final byte[]
AUTH_MAGIC

Magic value for proprietary OpenSSH private key.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean
allIntegers(ASN1Sequence sequence)

allIntegers returns true if the sequence holds only ASN1Integer types.

public static byte[]

Returns:

a byte array
encodePrivateKey
(AsymmetricKeyParameter
the cipher parameters.
params
)

Encode a cipher parameters into an OpenSSH private key.

public static AsymmetricKeyParameter

Returns:

A cipher parameters instance.
parsePrivateKeyBlob
(byte[]
The key.
blob
)

Parse a private key.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTH_MAGICback to summary
pack-priv static final byte[] AUTH_MAGIC

Magic value for proprietary OpenSSH private key.

Constructor Detail

OpenSSHPrivateKeyUtilback to summary
private OpenSSHPrivateKeyUtil()

Method Detail

allIntegersback to summary
private static boolean allIntegers(ASN1Sequence sequence)

allIntegers returns true if the sequence holds only ASN1Integer types.

encodePrivateKeyback to summary
public static byte[] encodePrivateKey(AsymmetricKeyParameter params) throws IOException

Encode a cipher parameters into an OpenSSH private key. This does not add headers like ----BEGIN RSA PRIVATE KEY----

Parameters
params:AsymmetricKeyParameter

the cipher parameters.

Returns:byte[]

a byte array

parsePrivateKeyBlobback to summary
public static AsymmetricKeyParameter parsePrivateKeyBlob(byte[] blob)

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:byte[]

The key.

Returns:AsymmetricKeyParameter

A cipher parameters instance.