public final class KeyUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static EnumMap<KeyEncryptionAlgorithm,Integer> |
KEY_ENCRYPTION_BITS |
protected static EnumMap<SignatureAlgorithm,Integer> |
SIGNATURE_ALGORITHM_BITS |
| Modifier and Type | Method and Description |
|---|---|
static SecretKey |
createSecretKeyFromSecret(String secret) |
static PublicKey |
decodeCertificate(String pemEncoded)
Decode a PEM encoded certificate string to an RSA PublicKey
|
static PrivateKey |
decodeDecryptionPrivateKey(String pemEncoded)
Decode a decryption PEM private key
|
static PrivateKey |
decodeDecryptionPrivateKey(String pemEncoded,
KeyEncryptionAlgorithm algo)
Decode a decryption PEM private key
|
static PublicKey |
decodeEncryptionPublicKey(String pemEncoded,
KeyEncryptionAlgorithm algo) |
static PublicKey |
decodeJWKSPublicKey(String jwksValue)
Deprecated.
|
static PrivateKey |
decodePrivateKey(String pemEncoded)
Decode a PEM RSA private key
|
static PrivateKey |
decodePrivateKey(String pemEncoded,
SignatureAlgorithm algo)
Decode a PEM private key
|
static PublicKey |
decodePublicKey(String pemEncoded)
Decode a PEM encoded public key string to an RSA PublicKey
|
static PublicKey |
decodePublicKey(String pemEncoded,
SignatureAlgorithm algo)
Decode a PEM encoded public key string to an RSA or EllipticCurve PublicKey
|
static KeyPair |
generateKeyPair(int keySize) |
static KeyPair |
generateKeyPair(int keySize,
SignatureAlgorithm algo) |
static SecretKey |
generateSecretKey(KeyEncryptionAlgorithm algo)
Generates a SecretKey.
|
static SecretKey |
generateSecretKey(SignatureAlgorithm algo)
Generates a SecretKey.
|
static X509Certificate |
getCertificate(String pemEncoded)
Decode a PEM encoded certificate string to X509Certificate
|
static List<org.jose4j.jwk.JsonWebKey> |
loadJsonWebKeys(String content) |
static PrivateKey |
readDecryptionPrivateKey(String pemResName) |
static PrivateKey |
readDecryptionPrivateKey(String pemResName,
KeyEncryptionAlgorithm algo) |
static Key |
readEncryptionKey(String location,
String kid) |
static Key |
readEncryptionKey(String location,
String kid,
KeyEncryptionAlgorithm alg) |
static PublicKey |
readEncryptionPublicKey(String pemResName) |
static PublicKey |
readEncryptionPublicKey(String pemResName,
KeyEncryptionAlgorithm algo) |
static PrivateKey |
readPrivateKey(String pemResName) |
static PrivateKey |
readPrivateKey(String pemResName,
SignatureAlgorithm algo) |
static PublicKey |
readPublicKey(String pemResName) |
static PublicKey |
readPublicKey(String pemResName,
SignatureAlgorithm algo) |
static Key |
readSigningKey(String location,
String kid) |
static Key |
readSigningKey(String location,
String kid,
SignatureAlgorithm alg) |
static String |
removePemKeyBeginEnd(String pem)
Strip any -----BEGIN*KEY...
|
protected static final EnumMap<KeyEncryptionAlgorithm,Integer> KEY_ENCRYPTION_BITS
protected static final EnumMap<SignatureAlgorithm,Integer> SIGNATURE_ALGORITHM_BITS
public static PrivateKey readPrivateKey(String pemResName) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PrivateKey readPrivateKey(String pemResName, SignatureAlgorithm algo) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PrivateKey readDecryptionPrivateKey(String pemResName) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PrivateKey readDecryptionPrivateKey(String pemResName, KeyEncryptionAlgorithm algo) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PublicKey readPublicKey(String pemResName) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PublicKey readPublicKey(String pemResName, SignatureAlgorithm algo) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PublicKey readEncryptionPublicKey(String pemResName) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static PublicKey readEncryptionPublicKey(String pemResName, KeyEncryptionAlgorithm algo) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException
NoSuchAlgorithmExceptionpublic static KeyPair generateKeyPair(int keySize, SignatureAlgorithm algo) throws NoSuchAlgorithmException
NoSuchAlgorithmExceptionpublic static PrivateKey decodePrivateKey(String pemEncoded) throws GeneralSecurityException
pemEncoded - - pem string for keyGeneralSecurityException - - on failure to decode and create keypublic static PrivateKey decodePrivateKey(String pemEncoded, SignatureAlgorithm algo) throws GeneralSecurityException
pemEncoded - - pem string for keyalgo - - signature algorithmGeneralSecurityException - - on failure to decode and create keypublic static PrivateKey decodeDecryptionPrivateKey(String pemEncoded) throws GeneralSecurityException
pemEncoded - - pem string for keyGeneralSecurityException - - on failure to decode and create keypublic static PrivateKey decodeDecryptionPrivateKey(String pemEncoded, KeyEncryptionAlgorithm algo) throws GeneralSecurityException
pemEncoded - - pem string for keyalgo - - key encryption algorithmGeneralSecurityException - - on failure to decode and create key@Deprecated public static PublicKey decodeJWKSPublicKey(String jwksValue) throws GeneralSecurityException
jwksValue - - JWKS string valueGeneralSecurityException - when RSA security is not supported or public key cannot be decodedpublic static PublicKey decodePublicKey(String pemEncoded) throws GeneralSecurityException
pemEncoded - - PEM string for public keyGeneralSecurityException - on decode failurepublic static SecretKey generateSecretKey(KeyEncryptionAlgorithm algo) throws InvalidAlgorithmParameterException
algo - key encryption algorithm.InvalidAlgorithmParameterException - algorithm not found.public static SecretKey generateSecretKey(SignatureAlgorithm algo) throws InvalidAlgorithmParameterException
algo - signature algorithm.InvalidAlgorithmParameterException - algorithm not found.public static PublicKey decodePublicKey(String pemEncoded, SignatureAlgorithm algo) throws GeneralSecurityException
pemEncoded - - PEM string for public keyalgo - signature algorithmGeneralSecurityException - on decode failurepublic static PublicKey decodeEncryptionPublicKey(String pemEncoded, KeyEncryptionAlgorithm algo) throws GeneralSecurityException
GeneralSecurityExceptionpublic static PublicKey decodeCertificate(String pemEncoded) throws GeneralSecurityException
pemEncoded - - PEM string for certificateGeneralSecurityException - on decode failurepublic static X509Certificate getCertificate(String pemEncoded) throws GeneralSecurityException
pemEncoded - - PEM string for certificateGeneralSecurityException - on decode failurepublic static String removePemKeyBeginEnd(String pem)
pem - encoded string with option header/footerpublic static Key readEncryptionKey(String location, String kid) throws IOException
IOExceptionpublic static Key readEncryptionKey(String location, String kid, KeyEncryptionAlgorithm alg) throws IOException
IOExceptionpublic static Key readSigningKey(String location, String kid) throws IOException
IOExceptionpublic static Key readSigningKey(String location, String kid, SignatureAlgorithm alg) throws IOException
IOExceptionCopyright © 2018–2021. All rights reserved.