public static SecretKey generateKey(String cipherAlgorithm) throws NoSuchAlgorithmException {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(cipherAlgorithm);
        keyGenerator.init(secureRandom);

        return keyGenerator.generateKey();
    }
public static SecretKey generateKey ( String cipherAlgorithm ) throws NoSuchAlgorithmException { KeyGenerator keyGenerator = KeyGenerator . getInstance ( cipherAlgorithm ) ; keyGenerator . init ( secureRandom ) ; return keyGenerator . generateKey ( ) ; }
Generates a random encryption key.

@param cipherAlgorithm the cipher algorithm the key will be used with. Will determine the key size
@return the generated key