public final class KeySupport
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
keyMatchAlgorithms
Maps key algorithms to the signing algorithm used in the key matching function.
|
| Modifier | Constructor and Description |
|---|---|
private |
KeySupport()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static java.security.interfaces.DSAPrivateKey |
buildJavaDSAPrivateKey(java.lang.String base64EncodedKey)
Build Java DSA private key from base64 encoding.
|
static java.security.interfaces.DSAPublicKey |
buildJavaDSAPublicKey(java.lang.String base64EncodedKey)
Build Java DSA public key from base64 encoding.
|
static java.security.interfaces.ECPrivateKey |
buildJavaECPrivateKey(java.lang.String base64EncodedKey)
Build Java EC private key from base64 encoding.
|
static java.security.interfaces.ECPublicKey |
buildJavaECPublicKey(java.lang.String base64EncodedKey)
Build Java EC public key from base64 encoding.
|
static java.security.PrivateKey |
buildJavaPrivateKey(java.lang.String base64EncodedKey)
Build Java private key from base64 encoding.
|
static java.security.interfaces.RSAPrivateKey |
buildJavaRSAPrivateKey(java.lang.String base64EncodedKey)
Build Java RSA private key from base64 encoding.
|
static java.security.interfaces.RSAPublicKey |
buildJavaRSAPublicKey(java.lang.String base64EncodedKey)
Build Java RSA public key from base64 encoding.
|
static java.security.PublicKey |
buildKey(java.security.spec.KeySpec keySpec,
java.lang.String keyAlgorithm)
Generates a public key from the given key spec.
|
static java.security.PrivateKey |
decodePrivateKey(byte[] key,
char[] password)
Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats.
|
static java.security.PrivateKey |
decodePrivateKey(java.io.File key,
char[] password)
Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats.
|
static java.security.PublicKey |
decodePublicKey(byte[] key)
Decodes RSA/DSA public keys in DER-encoded "SubjectPublicKeyInfo" format.
|
static javax.crypto.SecretKey |
decodeSecretKey(byte[] key,
java.lang.String algorithm)
Produces SecretKey instances specified as a raw byte[] plus a JCA key algorithm.
|
static java.security.PublicKey |
derivePublicKey(java.security.PrivateKey key)
Derives the public key from either a DSA or RSA private key.
|
static javax.crypto.SecretKey |
generateKey(java.lang.String algo,
int keyLength,
java.lang.String provider)
Generate a random symmetric key.
|
static java.security.KeyPair |
generateKeyPair(java.lang.String algo,
int keyLength,
java.lang.String provider)
Generate a random asymmetric key pair.
|
static java.lang.Integer |
getKeyLength(java.security.Key key)
Get the key length in bits of the specified key.
|
private static org.slf4j.Logger |
getLogger()
Get an SLF4J Logger.
|
static boolean |
matchKeyPair(java.security.PublicKey pubKey,
java.security.PrivateKey privKey)
Compare the supplied public and private keys, and determine if they correspond to the same key pair.
|
private static java.util.Map<java.lang.String,java.lang.String> keyMatchAlgorithms
@Nullable
public static java.lang.Integer getKeyLength(@Nonnull
java.security.Key key)
key - the key to evaluate@Nonnull
public static javax.crypto.SecretKey decodeSecretKey(@Nonnull
byte[] key,
@Nonnull
java.lang.String algorithm)
throws java.security.KeyException
key - the raw secret key bytesalgorithm - the JCA key algorithmjava.security.KeyException - thrown if the key can not be decoded@Nonnull
public static java.security.PublicKey decodePublicKey(@Nonnull
byte[] key)
throws java.security.KeyException
key - encoded keyjava.security.KeyException - thrown if the key cannot be decoded@Nonnull
public static java.security.PrivateKey decodePrivateKey(@Nonnull
java.io.File key,
@Nullable
char[] password)
throws java.security.KeyException
key - encoded keypassword - decryption password or null if the key is not encryptedjava.security.KeyException - thrown if the key cannot be decoded@Nonnull
public static java.security.PrivateKey decodePrivateKey(@Nonnull
byte[] key,
@Nullable
char[] password)
throws java.security.KeyException
key - encoded keypassword - decryption password or null if the key is not encryptedjava.security.KeyException - thrown if the key cannot be decoded@Nonnull
public static java.security.PublicKey derivePublicKey(@Nonnull
java.security.PrivateKey key)
throws java.security.KeyException
key - the private key to derive the public key fromjava.security.KeyException - 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 java.security.interfaces.DSAPublicKey buildJavaDSAPublicKey(@Nonnull
java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded DSA public keyjava.security.KeyException - thrown if there is an error constructing key@Nonnull
public static java.security.interfaces.RSAPublicKey buildJavaRSAPublicKey(@Nonnull
java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded RSA public keyjava.security.KeyException - thrown if there is an error constructing key@Nonnull
public static java.security.interfaces.ECPublicKey buildJavaECPublicKey(@Nonnull
java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded EC public keyjava.security.KeyException - thrown if there is an error constructing key@Nonnull
public static java.security.interfaces.RSAPrivateKey buildJavaRSAPrivateKey(@Nonnull
java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded RSA private keyjava.security.KeyException - thrown if there is an error constructing key@Nonnull
public static java.security.interfaces.DSAPrivateKey buildJavaDSAPrivateKey(@Nonnull
java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded DSA private keyjava.security.KeyException - thrown if there is an error constructing keypublic static java.security.interfaces.ECPrivateKey buildJavaECPrivateKey(java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded EC private keyjava.security.KeyException - thrown if there is an error constructing key@Nonnull
public static java.security.PrivateKey buildJavaPrivateKey(@Nonnull
java.lang.String base64EncodedKey)
throws java.security.KeyException
base64EncodedKey - base64-encoded private keyjava.security.KeyException - thrown if there is an error constructing key@Nonnull
public static java.security.PublicKey buildKey(@Nullable
java.security.spec.KeySpec keySpec,
@Nonnull
java.lang.String keyAlgorithm)
throws java.security.KeyException
keySpec - KeySpec specification for the keykeyAlgorithm - key generation algorithm, only DSA, RSA, and EC supportedPublicKeyjava.security.KeyException - thrown if the key algorithm is not supported by the JCA or the key spec does not contain
valid information@Nonnull
public static javax.crypto.SecretKey generateKey(@Nonnull
java.lang.String algo,
int keyLength,
@Nullable
java.lang.String provider)
throws java.security.NoSuchAlgorithmException,
java.security.NoSuchProviderException
algo - key algorithmkeyLength - key lengthprovider - JCA providerjava.security.NoSuchAlgorithmException - algorithm not foundjava.security.NoSuchProviderException - provider not found@Nonnull
public static java.security.KeyPair generateKeyPair(@Nonnull
java.lang.String algo,
int keyLength,
@Nullable
java.lang.String provider)
throws java.security.NoSuchAlgorithmException,
java.security.NoSuchProviderException
algo - key algorithmkeyLength - key lengthprovider - JCA providerjava.security.NoSuchAlgorithmException - algorithm not foundjava.security.NoSuchProviderException - provider not foundpublic static boolean matchKeyPair(@Nonnull
java.security.PublicKey pubKey,
@Nonnull
java.security.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 unknown@Nonnull private static org.slf4j.Logger getLogger()