public class KeyUtils
extends java.lang.Object
| Constructor and Description |
|---|
KeyUtils() |
| Modifier and Type | Method and Description |
|---|---|
static javax.crypto.SecretKey |
decryptKey(java.lang.String encodedKey,
java.lang.String algorithm,
java.security.Provider provider,
java.security.PrivateKey privateKey) |
static byte[] |
derEncodeBigInteger(java.math.BigInteger value)
Encodes a
BigInteger in DER format |
static byte[] |
derEncodeRSAPublicKey(java.security.interfaces.RSAPublicKey pubkey)
Encodes an RSA public key in DER format.
|
static byte[] |
derEncodeSequence(java.util.List<byte[]> objects)
Encodes a list of objects into a DER "sequence".
|
static byte[] |
derEncodeValue(byte type,
byte[] bytes)
Encodes a DER value with the proper length specifier.
|
static java.lang.String |
encryptKey(javax.crypto.SecretKey key,
java.security.Provider provider,
java.security.PublicKey publicKey) |
static byte[] |
extractSubjectKeyIdentifier(byte[] derSki) |
static java.lang.String |
getRsaPublicKeyFingerprint(java.security.interfaces.RSAPublicKey pubKey,
java.security.Provider provider)
Computes the fingerprint of an RSA public key.
|
static java.security.KeyPair |
rsaKeyPairFromBase64(java.lang.String publicKey,
java.lang.String privateKey)
Constructs an RSA KeyPair from base-64 encoded key material.
|
static java.lang.String |
signMetadata(java.util.Map<java.lang.String,java.lang.String> metadata,
java.security.interfaces.RSAPrivateKey privateKey,
java.security.Provider provider) |
static java.lang.String |
toHexPadded(byte[] data)
Transforms a byte sequence into a sequence of hex digits, MSB first.
|
static byte[] |
urlSafeDecodeBase64(java.lang.String b64Data)
Uses the 'base64url' encoding from RFC4648 to decode a string to a byte array.
|
static java.lang.String |
urlSafeEncodeBase64(byte[] data)
Uses the 'base64url' encoding from RFC4648 to encode a byte array to a string.
|
public static java.lang.String getRsaPublicKeyFingerprint(java.security.interfaces.RSAPublicKey pubKey,
java.security.Provider provider)
throws java.security.NoSuchAlgorithmException
pubKey - the RSA public key to fingerprintjava.security.NoSuchAlgorithmException - if the SHA1 algorithm could not be initialized.public static java.lang.String toHexPadded(byte[] data)
data - the bytes to encode into hexpublic static byte[] derEncodeBigInteger(java.math.BigInteger value)
BigInteger in DER formatvalue - the value to encodepublic static byte[] derEncodeValue(byte type,
byte[] bytes)
type - the DER type specifier bytebytes - the bytes to encodepublic static byte[] derEncodeRSAPublicKey(java.security.interfaces.RSAPublicKey pubkey)
pubkey - the RSA public key to encode.public static byte[] derEncodeSequence(java.util.List<byte[]> objects)
objects - the DER encoded objects to sequence.public static java.security.KeyPair rsaKeyPairFromBase64(java.lang.String publicKey,
java.lang.String privateKey)
throws java.security.GeneralSecurityException
publicKey - The Base-64 encoded RSA public key in X.509 format.privateKey - The Base-64 encoded RSA private key in PKCS#8 format.java.security.GeneralSecurityExceptionpublic static javax.crypto.SecretKey decryptKey(java.lang.String encodedKey,
java.lang.String algorithm,
java.security.Provider provider,
java.security.PrivateKey privateKey)
public static java.lang.String encryptKey(javax.crypto.SecretKey key,
java.security.Provider provider,
java.security.PublicKey publicKey)
throws java.security.GeneralSecurityException
java.security.GeneralSecurityExceptionpublic static java.lang.String urlSafeEncodeBase64(byte[] data)
data - the byte array to encodepublic static byte[] urlSafeDecodeBase64(java.lang.String b64Data)
b64Data - the Base-64 encoded string to decodepublic static java.lang.String signMetadata(java.util.Map<java.lang.String,java.lang.String> metadata,
java.security.interfaces.RSAPrivateKey privateKey,
java.security.Provider provider)
public static byte[] extractSubjectKeyIdentifier(byte[] derSki)