java.lang.Object
org.seppiko.commons.utils.crypto.KeyGeneratorUtil
Key and KeyPair Generator object util And SecureRandom object utility
- Author:
- Leonard Woo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic AlgorithmParameterGeneratoralgorithmParameterGenerator(String algorithm) Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.static AlgorithmParameterGeneratoralgorithmParameterGenerator(String algorithm, Provider provider) Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.static KeyGeneratorkeyGenerator(String algorithm) Returns a KeyGenerator object that generates secret keys for the specified algorithm.static KeyGeneratorkeyGenerator(String algorithm, Provider provider) Returns a KeyGenerator object that generates secret keys for the specified algorithm.static SecretKeykeyGenerator(String algorithm, Provider provider, int keySize) Cryptographic key generatorstatic KeyPairGeneratorkeyPairGenerator(String algorithm) Returns a KeyPairGenerator object that generates public/private key pairs for the specified algorithm.static KeyPairGeneratorkeyPairGenerator(String algorithm, Provider provider) Returns a KeyPairGenerator object that generates public/private key pairs for the specified * algorithm.static KeyPairkeyPairGenerator(String algorithm, Provider provider, int keySize) Asymmetric cryptographic key pair generatorstatic KeyPairkeyPairGenerator(String algorithm, Provider provider, AlgorithmParameterSpec params) Asymmetric cryptographic key pair generatorstatic KeyPairkeyPairGenerator(String algorithm, Provider provider, AlgorithmParameterSpec params, SecureRandom secureRandom) Asymmetric cryptographic key pair generatorstatic KeyPairkeyPairGeneratorWithoutInitialize(String algorithm) Signature cryptographic key pair generatorstatic KeyPairkeyPairGeneratorWithoutInitialize(String algorithm, Provider provider) Signature cryptographic key pair generatorstatic SecureRandomReturns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.static SecureRandomsecureRandom(String algorithm) Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.static SecureRandomsecureRandom(String algorithm, Provider provider) Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.static SecureRandomsecureRandom(String algorithm, Provider provider, SecureRandomParameters params) Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.static byte[]secureRandom(String algorithm, Provider provider, SecureRandomParameters params, int seedSize) Get secure random bytes
-
Method Details
-
keyGenerator
public static KeyGenerator keyGenerator(String algorithm) throws NoSuchAlgorithmException, NullPointerException Returns a KeyGenerator object that generates secret keys for the specified algorithm.- Parameters:
algorithm- the standard name of the requested key algorithm- Returns:
- new KeyGenerator instance
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyGeneratorSpi implementation for the specified algorithmNullPointerException- if algorithm is null
-
keyGenerator
public static KeyGenerator keyGenerator(String algorithm, Provider provider) throws NoSuchAlgorithmException, NullPointerException, IllegalArgumentException Returns a KeyGenerator object that generates secret keys for the specified algorithm.- Parameters:
algorithm- the standard name of the requested key algorithmprovider- the provider- Returns:
- new KeyGenerator instance
- Throws:
NoSuchAlgorithmException- if a KeyGeneratorSpi implementation for the specified algorithm is not available from the specified Provider objectNullPointerException- if algorithm is nullIllegalArgumentException- if the provider is null
-
keyPairGenerator
public static KeyPairGenerator keyPairGenerator(String algorithm) throws NoSuchAlgorithmException, NullPointerException Returns a KeyPairGenerator object that generates public/private key pairs for the specified algorithm.- Parameters:
algorithm- the standard string name of the algorithm- Returns:
- the new KeyPairGenerator instance
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithmNullPointerException- if algorithm is null
-
keyPairGenerator
public static KeyPairGenerator keyPairGenerator(String algorithm, Provider provider) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException Returns a KeyPairGenerator object that generates public/private key pairs for the specified * algorithm.- Parameters:
algorithm- the standard string name of the algorithmprovider- the provider- Returns:
- the new KeyPairGenerator instance
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithmIllegalArgumentException- if the specified provider is nullNullPointerException- if algorithm is null
-
algorithmParameterGenerator
public static AlgorithmParameterGenerator algorithmParameterGenerator(String algorithm) throws NoSuchAlgorithmException, NullPointerException Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.- Parameters:
algorithm- the name of the algorithm this parameter generator is associated with- Returns:
- the new AlgorithmParameterGenerator instance
- Throws:
NoSuchAlgorithmException- if an AlgorithmParameterGeneratorSpi implementation for the specified algorithm is not available from the specified Provider objectNullPointerException- if algorithm is null
-
algorithmParameterGenerator
public static AlgorithmParameterGenerator algorithmParameterGenerator(String algorithm, Provider provider) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.- Parameters:
algorithm- the name of the algorithm this parameter generator is associated withprovider- the Provider- Returns:
- the new AlgorithmParameterGenerator instance
- Throws:
NoSuchAlgorithmException- if an AlgorithmParameterGeneratorSpi implementation for the specified algorithm is not available from the specified Provider objectIllegalArgumentException- if the specified provider is nullNullPointerException- if algorithm is null
-
keyGenerator
public static SecretKey keyGenerator(String algorithm, Provider provider, int keySize) throws NoSuchAlgorithmException, NullPointerException, IllegalArgumentException Cryptographic key generator- Parameters:
algorithm- the standard name of the requested key algorithmprovider- the provider, if use default provider is nullkeySize- key size- Returns:
- secret key byte array
- Throws:
NoSuchAlgorithmException- if a KeyGeneratorSpi implementation for the specified algorithm is not available from the specified Provider objectNullPointerException- if algorithm is nullIllegalArgumentException- if the provider is null
-
keyPairGeneratorWithoutInitialize
public static KeyPair keyPairGeneratorWithoutInitialize(String algorithm, Provider provider) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException Signature cryptographic key pair generator- Parameters:
algorithm- the standard string name of the algorithm.provider- the provider, if use default provider is null.- Returns:
- keypair instance.
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithm.IllegalArgumentException- if the provider is null.NullPointerException- if algorithm is null.- See Also:
-
keyPairGeneratorWithoutInitialize
public static KeyPair keyPairGeneratorWithoutInitialize(String algorithm) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException Signature cryptographic key pair generator- Parameters:
algorithm- the standard string name of the algorithm.- Returns:
- keypair instance.
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithm.IllegalArgumentException- if the provider is null.NullPointerException- if algorithm is null.- See Also:
-
keyPairGenerator
public static KeyPair keyPairGenerator(String algorithm, Provider provider, int keySize) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException Asymmetric cryptographic key pair generatorEvery implementation of the Java platform is required to support the following standard
KeyPairGeneratoralgorithms and keysizes in parentheses:DiffieHellman(1024, 2048, 4096)DSA(1024, 2048)RSA(1024, 2048, 4096)EdDSAOREd25519(255)Ed448(448)XDHORX25519(255)X448(448)
- Parameters:
algorithm- the standard string name of the algorithm.provider- the provider, if use default provider is null.keySize- the keysize. This is an algorithm-specific metric, such as modulus length, specified in number of bits.- Returns:
- keypair instance.
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithm.IllegalArgumentException- if the provider is null.NullPointerException- if algorithm is null.- See Also:
-
keyPairGenerator
public static KeyPair keyPairGenerator(String algorithm, Provider provider, AlgorithmParameterSpec params) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException, InvalidAlgorithmParameterException Asymmetric cryptographic key pair generator- Parameters:
algorithm- the standard string name of the algorithm.provider- the provider, if use default provider is null.params- the parameter set used to generate the keys.- Returns:
- keypair instance.
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithm.IllegalArgumentException- if the provider is null.NullPointerException- if algorithm is null.InvalidAlgorithmParameterException- if the given parameters are inappropriate for this key pair generator.- See Also:
-
keyPairGenerator
public static KeyPair keyPairGenerator(String algorithm, Provider provider, AlgorithmParameterSpec params, SecureRandom secureRandom) throws NoSuchAlgorithmException, IllegalArgumentException, NullPointerException, InvalidAlgorithmParameterException Asymmetric cryptographic key pair generator- Parameters:
algorithm- the standard string name of the algorithm.provider- the provider, if use default provider is null.params- the parameter set used to generate the keys.secureRandom- the source of randomness.- Returns:
- keypair instance.
- Throws:
NoSuchAlgorithmException- if no Provider supports a KeyPairGeneratorSpi implementation for the specified algorithm.IllegalArgumentException- if the provider is null.NullPointerException- if algorithm is null.InvalidAlgorithmParameterException- if the given parameters are inappropriate for this key pair generator.- See Also:
-
secureRandom
Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.- Returns:
- the new SecureRandom instance.
-
secureRandom
Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.- Parameters:
algorithm- the name of the RNG algorithm.- Returns:
- the new SecureRandom instance.
-
secureRandom
Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.- Parameters:
algorithm- the name of the RNG algorithm.provider- the provider.- Returns:
- the new SecureRandom instance.
-
secureRandom
public static SecureRandom secureRandom(String algorithm, Provider provider, SecureRandomParameters params) Returns a SecureRandom object that implements the specified Random Number Generator (RNG) algorithm.- Parameters:
algorithm- the name of the RNG algorithm.provider- the provider.params- the SecureRandomParameters the newly created SecureRandom object must support.- Returns:
- the new SecureRandom instance.
-
secureRandom
public static byte[] secureRandom(String algorithm, Provider provider, SecureRandomParameters params, int seedSize) Get secure random bytes- Parameters:
algorithm- the name of the RNG algorithm.provider- the provider.params- the SecureRandomParameters the newly created SecureRandom object must support.seedSize- the number of seed bytes to generate.- Returns:
- the seed bytes.
-