Java Utililty Methods Key Pair Create

List of utility methods to do Key Pair Create

Description

The list of methods to do Key Pair Create are organized into topic(s).

Method

KeygenerateKey()
generate Key
try {
    KeyGenerator kg = KeyGenerator.getInstance("DES");
    Key key = kg.generateKey();
    return key;
} catch (Exception e) {
    e.printStackTrace();
return null;
...
SecretKeygenerateKey()
generate Key
KeyGenerator gen;
try {
    gen = KeyGenerator.getInstance("AES");
} catch (NoSuchAlgorithmException e) {
    throw new IllegalStateException("Failed to get generator for algorithm", e);
gen.init(random);
return gen.generateKey();
...
KeygenerateKey(byte[] keyBytes)
generate Key
KeySpec keySpec = new DESKeySpec(keyBytes);
SecretKeyFactory factory = SecretKeyFactory.getInstance(DES);
return factory.generateSecret(keySpec);
KeygenerateKey(byte[] keyBytes)
generate Key
return new SecretKeySpec(keyBytes, AES);
KeygenerateKey(char[] password)
generate Key
return generateKey(password, generateSalt(128));
byte[]generateKey(final SecureRandom srand)
generate Key
final byte[] key = new byte[256 / 8];
srand.nextBytes(key);
return key;
SecretKeygenerateKey(final String password, final byte salt[])
Generates a key using the specified password and salt.
if (salt.length < SALT_LENGTH) {
    throw new Exception("Need a salt at least length " + SALT_LENGTH + ".");
return generateKey(password.toCharArray(), salt);
KeygenerateKey(SecureRandom sr, int size)
generate Key
byte[] bytes = new byte[size];
sr.nextBytes(bytes);
return new SecretKeySpec(bytes, "AES");
SecretKeygenerateKey(String algom, int keylength)
generate Key
try {
    KeyGenerator keygen = KeyGenerator.getInstance(algom);
    keygen.init(keylength);
    SecretKey deskey = keygen.generateKey();
    return deskey;
} catch (GeneralSecurityException e) {
    throw new RuntimeException(e);
SecretKeygenerateKey(String algorithm, int keySize)
Generate a SecretKey for the given symmetric algorithm and keysize Example: CipherUtils.generateKeyPair("AES", 128)
KeyGenerator secretKeyGenerator;
try {
    secretKeyGenerator = KeyGenerator.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException(e);
secretKeyGenerator.init(keySize);
return secretKeyGenerator.generateKey();
...