public final class KeySupport extends Object
Modifier and Type | Method and Description |
---|---|
static DSAPrivateKey |
buildJavaDSAPrivateKey(String base64EncodedKey)
Build Java DSA private key from base64 encoding.
|
static DSAPublicKey |
buildJavaDSAPublicKey(String base64EncodedKey)
Build Java DSA public key from base64 encoding.
|
static ECPrivateKey |
buildJavaECPrivateKey(String base64EncodedKey)
Build Java EC private key from base64 encoding.
|
static ECPublicKey |
buildJavaECPublicKey(String base64EncodedKey)
Build Java EC public key from base64 encoding.
|
static PrivateKey |
buildJavaPrivateKey(String base64EncodedKey)
Build Java private key from base64 encoding.
|
static RSAPrivateKey |
buildJavaRSAPrivateKey(String base64EncodedKey)
Build Java RSA private key from base64 encoding.
|
static RSAPublicKey |
buildJavaRSAPublicKey(String base64EncodedKey)
Build Java RSA public key from base64 encoding.
|
static PublicKey |
buildKey(KeySpec keySpec,
String keyAlgorithm)
Generates a public key from the given key spec.
|
static PrivateKey |
decodePrivateKey(byte[] key,
char[] password)
Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats.
|
static PrivateKey |
decodePrivateKey(File key,
char[] password)
Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats.
|
static PublicKey |
decodePublicKey(byte[] key)
Decodes RSA/DSA public keys in DER-encoded "SubjectPublicKeyInfo" format.
|
static SecretKey |
decodeSecretKey(byte[] key,
String algorithm)
Produces SecretKey instances specified as a raw byte[] plus a JCA key algorithm.
|
static PublicKey |
derivePublicKey(PrivateKey key)
Derives the public key from either a DSA or RSA private key.
|
static SecretKey |
generateKey(String algo,
int keyLength,
String provider)
Generate a random symmetric key.
|
static KeyPair |
generateKeyPair(String algo,
int keyLength,
String provider)
Generate a random asymmetric key pair.
|
static Integer |
getKeyLength(Key key)
Get the key length in bits of the specified key.
|
static boolean |
matchKeyPair(PublicKey pubKey,
PrivateKey privKey)
Compare the supplied public and private keys, and determine if they correspond to the same key pair.
|
@Nullable public static Integer getKeyLength(@Nonnull Key key)
key
- the key to evaluate@Nonnull public static SecretKey decodeSecretKey(@Nonnull byte[] key, @Nonnull String algorithm) throws KeyException
key
- the raw secret key bytesalgorithm
- the JCA key algorithmKeyException
- thrown if the key can not be decoded@Nonnull public static PublicKey decodePublicKey(@Nonnull byte[] key) throws KeyException
key
- encoded keyKeyException
- thrown if the key cannot be decoded@Nonnull public static PrivateKey decodePrivateKey(@Nonnull File key, @Nullable char[] password) throws KeyException
key
- encoded keypassword
- decryption password or null if the key is not encryptedKeyException
- thrown if the key cannot be decoded@Nonnull public static PrivateKey decodePrivateKey(@Nonnull byte[] key, @Nullable char[] password) throws KeyException
key
- encoded keypassword
- decryption password or null if the key is not encryptedKeyException
- thrown if the key cannot be decoded@Nonnull public static PublicKey derivePublicKey(@Nonnull PrivateKey key) throws KeyException
key
- the private key to derive the public key fromKeyException
- thrown if the given private key is not a DSA or RSA key or there is a problem generating the
public key@Nonnull public static DSAPublicKey buildJavaDSAPublicKey(@Nonnull String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded DSA public keyKeyException
- thrown if there is an error constructing key@Nonnull public static RSAPublicKey buildJavaRSAPublicKey(@Nonnull String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded RSA public keyKeyException
- thrown if there is an error constructing key@Nonnull public static ECPublicKey buildJavaECPublicKey(@Nonnull String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded EC public keyKeyException
- thrown if there is an error constructing key@Nonnull public static RSAPrivateKey buildJavaRSAPrivateKey(@Nonnull String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded RSA private keyKeyException
- thrown if there is an error constructing key@Nonnull public static DSAPrivateKey buildJavaDSAPrivateKey(@Nonnull String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded DSA private keyKeyException
- thrown if there is an error constructing keypublic static ECPrivateKey buildJavaECPrivateKey(String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded EC private keyKeyException
- thrown if there is an error constructing key@Nonnull public static PrivateKey buildJavaPrivateKey(@Nonnull String base64EncodedKey) throws KeyException
base64EncodedKey
- base64-encoded private keyKeyException
- thrown if there is an error constructing key@Nonnull public static PublicKey buildKey(@Nullable KeySpec keySpec, @Nonnull String keyAlgorithm) throws KeyException
keySpec
- KeySpec
specification for the keykeyAlgorithm
- key generation algorithm, only DSA, RSA, and EC supportedPublicKey
KeyException
- thrown if the key algorithm is not supported by the JCA or the key spec does not contain
valid information@Nonnull public static SecretKey generateKey(@Nonnull String algo, int keyLength, @Nullable String provider) throws NoSuchAlgorithmException, NoSuchProviderException
algo
- key algorithmkeyLength
- key lengthprovider
- JCA providerNoSuchAlgorithmException
- algorithm not foundNoSuchProviderException
- provider not found@Nonnull public static KeyPair generateKeyPair(@Nonnull String algo, int keyLength, @Nullable String provider) throws NoSuchAlgorithmException, NoSuchProviderException
algo
- key algorithmkeyLength
- key lengthprovider
- JCA providerNoSuchAlgorithmException
- algorithm not foundNoSuchProviderException
- provider not foundpublic static boolean matchKeyPair(@Nonnull PublicKey pubKey, @Nonnull PrivateKey privKey) throws SecurityException
pubKey
- the public keyprivKey
- the private keySecurityException
- if the keys can not be evaluated, or if the key algorithm is unsupported or unknownCopyright © 2016 JBoss by Red Hat. All rights reserved.