public final class KeyPairUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static byte[] |
SIGN_BYTES
Data used to verify key pairs.
|
| Modifier | Constructor and Description |
|---|---|
private |
KeyPairUtil()
Private constructor of utility class.
|
| Modifier and Type | Method and Description |
|---|---|
static java.security.PrivateKey |
decodePrivateKey(byte[] encodedKey)
Decodes an encoded private key in either PKCS#8 or OpenSSL "traditional" format in either DER or PEM encoding.
|
static java.security.PrivateKey |
decodePrivateKey(byte[] encryptedKey,
char[] password)
Decodes an encrypted private key.
|
static java.security.PublicKey |
decodePublicKey(byte[] encoded)
Decodes public keys formatted in an X.509 SubjectPublicKeyInfo structure in either PEM or DER encoding.
|
static boolean |
isKeyPair(java.security.interfaces.DSAPublicKey pubKey,
java.security.interfaces.DSAPrivateKey privKey)
Determines whether the given DSA public and private keys form a proper key pair by computing and verifying a
digital signature with the keys.
|
static boolean |
isKeyPair(java.security.interfaces.ECPublicKey pubKey,
java.security.interfaces.ECPrivateKey privKey)
Determines whether the given EC public and private keys form a proper key pair by computing and verifying a digital
signature with the keys.
|
static boolean |
isKeyPair(java.security.PublicKey pubKey,
java.security.PrivateKey privKey)
Determines whether the given public and private keys form a proper key pair by computing and verifying a digital
signature with the keys.
|
static boolean |
isKeyPair(java.security.interfaces.RSAPublicKey pubKey,
java.security.interfaces.RSAPrivateKey privKey)
Determines whether the given RSA public and private keys form a proper key pair by computing and verifying a
digital signature with the keys.
|
static int |
length(java.security.PrivateKey privKey)
Gets the length in bits of a private key where key size is dependent on the particulars of the algorithm.
|
static int |
length(java.security.PublicKey pubKey)
Gets the length in bits of a public key where key size is dependent on the particulars of the algorithm.
|
static java.security.PrivateKey |
readPrivateKey(java.io.File file)
Reads an encoded private key from a file.
|
static java.security.PrivateKey |
readPrivateKey(java.io.File file,
char[] password)
Reads an encrypted private key from a file.
|
static java.security.PrivateKey |
readPrivateKey(java.io.InputStream in)
Reads an encoded private key from an input stream.
|
static java.security.PrivateKey |
readPrivateKey(java.io.InputStream in,
char[] password)
Reads an encrypted private key from an input stream.
|
static java.security.PrivateKey |
readPrivateKey(java.lang.String path)
Reads an encoded private key from a file at the given path.
|
static java.security.PrivateKey |
readPrivateKey(java.lang.String path,
char[] password)
Reads an encrypted private key from a file at the given path.
|
static java.security.PublicKey |
readPublicKey(java.io.File file)
Reads a DER or PEM-encoded public key from a file.
|
static java.security.PublicKey |
readPublicKey(java.io.InputStream in)
Reads a DER or PEM-encoded public key from data in the given stream.
|
static java.security.PublicKey |
readPublicKey(java.lang.String path)
Reads a DER or PEM-encoded public key from a file.
|
public static int length(java.security.PublicKey pubKey)
pubKey - Public key.public static int length(java.security.PrivateKey privKey)
privKey - Private key.public static boolean isKeyPair(java.security.PublicKey pubKey,
java.security.PrivateKey privKey)
throws CryptoException
pubKey - DSA, RSA or EC public key.privKey - DSA, RSA, or EC private key.CryptoException - on key validation errors.public static boolean isKeyPair(java.security.interfaces.DSAPublicKey pubKey,
java.security.interfaces.DSAPrivateKey privKey)
throws CryptoException
pubKey - DSA public key.privKey - DSA private key.CryptoException - on key validation errors.public static boolean isKeyPair(java.security.interfaces.RSAPublicKey pubKey,
java.security.interfaces.RSAPrivateKey privKey)
throws CryptoException
pubKey - RSA public key.privKey - RSA private key.CryptoException - on key validation errors.public static boolean isKeyPair(java.security.interfaces.ECPublicKey pubKey,
java.security.interfaces.ECPrivateKey privKey)
throws CryptoException
pubKey - EC public key.privKey - EC private key.CryptoException - on key validation errors.public static java.security.PrivateKey readPrivateKey(java.lang.String path)
throws EncodingException,
StreamException
decodePrivateKey(byte[]) for supported asymmetric algorithms.path - Path to private key file.EncodingException - on key encoding errors.StreamException - on IO errors reading data from file.public static java.security.PrivateKey readPrivateKey(java.io.File file)
throws EncodingException,
StreamException
decodePrivateKey(byte[]) for supported asymmetric algorithms.file - Private key file.EncodingException - on key encoding errors.StreamException - on IO errors reading data from file.public static java.security.PrivateKey readPrivateKey(java.io.InputStream in)
throws EncodingException,
StreamException
decodePrivateKey(byte[]) for supported asymmetric algorithms.in - Input stream containing private key data.EncodingException - on key encoding errors.StreamException - on IO errors reading data from file.public static java.security.PrivateKey readPrivateKey(java.lang.String path,
char[] password)
throws EncodingException,
StreamException
decodePrivateKey(byte[]) for supported asymmetric algorithms.path - Path to private key file.password - Password used to encrypt private key.EncodingException - on key encoding errors.StreamException - on IO errors.public static java.security.PrivateKey readPrivateKey(java.io.File file,
char[] password)
throws EncodingException,
StreamException
decodePrivateKey(byte[]) for supported asymmetric algorithms.file - Private key file.password - Password used to encrypt private key.EncodingException - on key encoding errors.StreamException - on IO errors.public static java.security.PrivateKey readPrivateKey(java.io.InputStream in,
char[] password)
throws EncodingException,
StreamException
decodePrivateKey(byte[]) for supported asymmetric algorithms.in - Input stream containing private key data.password - Password used to encrypt private key.EncodingException - on key encoding errors.StreamException - on IO errors.public static java.security.PrivateKey decodePrivateKey(byte[] encodedKey)
throws EncodingException
encodedKey - Encoded private key data.EncodingException - on key encoding errors.public static java.security.PrivateKey decodePrivateKey(byte[] encryptedKey,
char[] password)
throws EncodingException
Keys from the following asymmetric algorithms are supported:
encryptedKey - Encrypted private key data.password - Password used to encrypt private key.EncodingException - on key encoding errors.public static java.security.PublicKey readPublicKey(java.lang.String path)
throws EncodingException,
StreamException
path - Path to DER or PEM-encoded public key file.EncodingException - on key encoding errors.StreamException - on IO errors.public static java.security.PublicKey readPublicKey(java.io.File file)
throws EncodingException,
StreamException
file - DER or PEM-encoded public key file.EncodingException - on key encoding errors.StreamException - on IO errors.public static java.security.PublicKey readPublicKey(java.io.InputStream in)
throws EncodingException,
StreamException
in - Input stream containing an encoded key.EncodingException - on key encoding errors.StreamException - on IO errors.public static java.security.PublicKey decodePublicKey(byte[] encoded)
throws EncodingException
encoded - Encoded public key bytes.EncodingException - on key encoding errors.