public final class CryptoUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static PrivateKey |
createPrivateKey(String algorithm,
KeySpec keySpec)
Returns a PrivateKey for the given algorithm and KeySpec.
|
static PublicKey |
createPublicKey(String algorithm,
KeySpec keySpec)
Returns a PublicKey for the given algorithm and KeySpec.
|
static KeyPair |
generateAsymmetricKeyPair(int keySize,
String algorithm)
Generates a new asymmetric key pair for the given algorithm and key size.
|
static KeyPair |
generateAsymmetricKeyPair(int keySize,
String algorithm,
String providerName,
Provider provider)
Generates a new asymmetric key pair for the given algorithm, key size, and provider.
|
static KeyPair |
generateAsymmetricKeyPair(String algorithm)
Generates a new asymmetric key pair for the given algorithm.
|
static KeyPair |
generateAsymmetricKeyPair(String algorithm,
String providerName,
Provider provider)
Generates a new asymmetric key pair for the given algorithm and provider.
|
static SecretKey |
generateSecretKey(int keySize,
String algorithm)
Generates a new secret key for the given algorithm and key size.
|
static SecretKey |
generateSecretKey(int keySize,
String algorithm,
String providerName,
Provider provider)
Generates a new secret key for the given algorithm, key size, and provider.
|
static SecretKey |
generateSecretKey(String algorithm)
Generates a new secret key for the given algorithm.
|
static SecretKey |
generateSecretKey(String algorithm,
String providerName,
Provider provider)
Generates a new secret key for the given algorithm and provider.
|
static <T extends KeySpec> |
getKeySpec(Key key,
Class<T> keySpec)
Returns a KeySpec for the given key and KeySpec implementation class.
|
static SecretKey |
getSecretKeyFromRawKey(byte[] rawKey,
String algorithm)
Creates a secret key from the supplied raw key byte array.
|
static SecretKey |
getSecretKeyFromTextKey(String textKey,
String algorithm)
Creates a secret key from the supplied text.
|
static SecretKey |
getSecretKeyFromTextKey(String textKey,
String algorithm,
TextEncoder textEncoder)
Creates a secret key from the supplied text.
|
public static SecretKey generateSecretKey(String algorithm) throws NoSuchAlgorithmException
algorithm - the algorithm that will be used for key generationNoSuchAlgorithmException - NoSuchAlgorithmExceptionpublic static SecretKey generateSecretKey(int keySize, String algorithm) throws NoSuchAlgorithmException
keySize - the size of the key in bitsalgorithm - the algorithm that will be used for key generationNoSuchAlgorithmException - NoSuchAlgorithmExceptionpublic static SecretKey generateSecretKey(String algorithm, String providerName, Provider provider) throws NoSuchAlgorithmException, NoSuchProviderException
algorithm - the algorithm that will be used for key generationproviderName - the name of the JCE-compliant provider (may be null)provider - the JCE-compliant provider (may be null)NoSuchAlgorithmException - NoSuchAlgorithmExceptionNoSuchProviderException - NoSuchProviderExceptionpublic static SecretKey generateSecretKey(int keySize, String algorithm, String providerName, Provider provider) throws NoSuchAlgorithmException, NoSuchProviderException
keySize - the size of the key in bitsalgorithm - the algorithm that will be used for key generationproviderName - the name of the JCE-compliant provider (may be null)provider - the JCE-compliant provider (may be null)NoSuchAlgorithmException - NoSuchAlgorithmExceptionNoSuchProviderException - NoSuchProviderExceptionpublic static KeyPair generateAsymmetricKeyPair(String algorithm) throws NoSuchAlgorithmException
algorithm - the algorithm that will be used for key generationNoSuchAlgorithmException - NoSuchAlgorithmExceptionpublic static KeyPair generateAsymmetricKeyPair(int keySize, String algorithm) throws NoSuchAlgorithmException
keySize - the size of the key in bitsalgorithm - the algorithm that will be used for key generationNoSuchAlgorithmException - NoSuchAlgorithmExceptionpublic static KeyPair generateAsymmetricKeyPair(String algorithm, String providerName, Provider provider) throws NoSuchAlgorithmException, NoSuchProviderException
algorithm - the algorithm that will be used for key generationproviderName - the name of the JCE-compliant provider (may be null)provider - the JCE-compliant provider (may be null)NoSuchAlgorithmException - NoSuchAlgorithmExceptionNoSuchProviderException - NoSuchProviderExceptionpublic static KeyPair generateAsymmetricKeyPair(int keySize, String algorithm, String providerName, Provider provider) throws NoSuchAlgorithmException, NoSuchProviderException
keySize - the size of the key in bitsalgorithm - the algorithm that will be used for key generationproviderName - the name of the JCE-compliant provider (may be null)provider - the JCE-compliant provider (may be null)NoSuchAlgorithmException - NoSuchAlgorithmExceptionNoSuchProviderException - NoSuchProviderExceptionpublic static SecretKey getSecretKeyFromTextKey(String textKey, String algorithm)
textKey - the text keyalgorithm - the algorithm that the will be used for key generationpublic static SecretKey getSecretKeyFromTextKey(String textKey, String algorithm, TextEncoder textEncoder)
textKey - the text keyalgorithm - the algorithm that will be used for key generationtextEncoder - the text encoder that will be used to decode the text key (if null, the
raw bytes will be used).public static SecretKey getSecretKeyFromRawKey(byte[] rawKey, String algorithm)
rawKey - the raw key byte arrayalgorithm - the algorithm that will be used for key generationpublic static PublicKey createPublicKey(String algorithm, KeySpec keySpec) throws InvalidKeySpecException, NoSuchAlgorithmException
algorithm - the algorithmkeySpec - the KeySpecInvalidKeySpecException - InvalidKeySpecExceptionNoSuchAlgorithmException - NoSuchAlgorithmExceptionpublic static PrivateKey createPrivateKey(String algorithm, KeySpec keySpec) throws InvalidKeySpecException, NoSuchAlgorithmException
algorithm - the algorithmkeySpec - the KeySpecInvalidKeySpecException - InvalidKeySpecExceptionNoSuchAlgorithmException - NoSuchAlgorithmExceptionpublic static <T extends KeySpec> T getKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException, NoSuchAlgorithmException
T - the KeySpec implementation typekey - the KeykeySpec - the KeySpec implementation classInvalidKeySpecException - InvalidKeySpecExceptionNoSuchAlgorithmException - NoSuchAlgorithmException