public final class KeyPairUtil extends Object
Modifier and Type | Method and Description |
---|---|
static PrivateKey |
decodePrivateKey(byte[] encodedKey)
Decodes an encoded private key in either PKCS#8 or OpenSSL "traditional"
format in either DER or PEM encoding.
|
static PrivateKey |
decodePrivateKey(byte[] encryptedKey,
char[] password)
Decodes an encrypted private key.
|
static PublicKey |
decodePublicKey(byte[] encoded)
Decodes public keys formatted in an X.509 SubjectPublicKeyInfo structure in
either PEM or DER encoding.
|
static boolean |
isKeyPair(DSAPublicKey pubKey,
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(ECPublicKey pubKey,
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(PublicKey pubKey,
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(RSAPublicKey pubKey,
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(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(PublicKey pubKey)
Gets the length in bits of a public key where key size is dependent on the
particulars of the algorithm.
|
static PrivateKey |
readPrivateKey(File file)
Reads an encoded private key from a file.
|
static PrivateKey |
readPrivateKey(File file,
char[] password)
Reads an encrypted private key from a file.
|
static PrivateKey |
readPrivateKey(InputStream in)
Reads an encoded private key from an input stream.
|
static PrivateKey |
readPrivateKey(InputStream in,
char[] password)
Reads an encrypted private key from an input stream.
|
static PrivateKey |
readPrivateKey(String path)
Reads an encoded private key from a file at the given path.
|
static PrivateKey |
readPrivateKey(String path,
char[] password)
Reads an encrypted private key from a file at the given path.
|
static PublicKey |
readPublicKey(File file)
Reads a DER or PEM-encoded public key from a file.
|
static PublicKey |
readPublicKey(InputStream in)
Reads a DER or PEM-encoded public key from data in the given stream.
|
static PublicKey |
readPublicKey(String path)
Reads a DER or PEM-encoded public key from a file.
|
public static int length(PublicKey pubKey)
pubKey
- Public key.public static int length(PrivateKey privKey)
privKey
- Private key.public static boolean isKeyPair(PublicKey pubKey, PrivateKey privKey)
pubKey
- DSA, RSA or EC public key.privKey
- DSA, RSA, or EC private key.public static boolean isKeyPair(DSAPublicKey pubKey, DSAPrivateKey privKey)
pubKey
- DSA public key.privKey
- DSA private key.public static boolean isKeyPair(RSAPublicKey pubKey, RSAPrivateKey privKey)
pubKey
- RSA public key.privKey
- RSA private key.public static boolean isKeyPair(ECPublicKey pubKey, ECPrivateKey privKey)
pubKey
- EC public key.privKey
- EC private key.public static PrivateKey readPrivateKey(String path) throws IOException
decodePrivateKey(byte[])
for supported asymmetric algorithms.path
- Path to private key file.IOException
- On IO errors reading data from file.public static PrivateKey readPrivateKey(File file) throws IOException
decodePrivateKey(byte[])
for supported asymmetric algorithms.file
- Private key file.IOException
- On IO errors reading data from file.public static PrivateKey readPrivateKey(InputStream in) throws IOException
decodePrivateKey(byte[])
for supported asymmetric algorithms.in
- Input stream containing private key data.IOException
- On IO errors reading data from file.public static PrivateKey readPrivateKey(String path, char[] password) throws IOException
decodePrivateKey(byte[])
for supported asymmetric algorithms.path
- Path to private key file.password
- Password used to encrypt private key.IOException
- On IO errors reading data from file.public static PrivateKey readPrivateKey(File file, char[] password) throws IOException
decodePrivateKey(byte[])
for supported asymmetric algorithms.file
- Private key file.password
- Password used to encrypt private key.IOException
- On IO errors reading data from file.public static PrivateKey readPrivateKey(InputStream in, char[] password) throws IOException
decodePrivateKey(byte[])
for supported asymmetric algorithms.in
- Input stream containing private key data.password
- Password used to encrypt private key.IOException
- On IO errors reading data from file.public static PrivateKey decodePrivateKey(byte[] encodedKey)
encodedKey
- Encoded private key data.public static PrivateKey decodePrivateKey(byte[] encryptedKey, char[] password)
Keys from the following asymmetric algorithms are supported:
encryptedKey
- Encrypted private key data.password
- Password used to encrypt private key.public static PublicKey readPublicKey(String path) throws IOException
path
- Path to DER or PEM-encoded public key file.IOException
- On IO errorspublic static PublicKey readPublicKey(File file) throws IOException
file
- DER or PEM-encoded public key file.IOException
- On IO errorspublic static PublicKey readPublicKey(InputStream in) throws IOException
in
- Input stream containing an encoded key.IOException
- On IO errorspublic static PublicKey decodePublicKey(byte[] encoded)
encoded
- Encoded public key bytes.Copyright © 2016 JBoss by Red Hat. All rights reserved.