List of utility methods to do Key Create
SecretKey | getKeyFromPassphrase(String passphrase, byte[] salt) get Key From Passphrase PBEKeySpec keyspec = new PBEKeySpec(passphrase.toCharArray(), salt, 100); SecretKeyFactory skf = SecretKeyFactory .getInstance("PBEWITHSHA1AND128BITAES-CBC-BC"); return skf.generateSecret(keyspec); |
SecretKey | getKeyFromPassphrase(String passphrase, byte[] salt, int iterations) get Key From Passphrase PBEKeySpec keyspec = new PBEKeySpec(passphrase.toCharArray(), salt, iterations); SecretKeyFactory skf = SecretKeyFactory .getInstance("PBEWITHSHA1AND128BITAES-CBC-BC"); return skf.generateSecret(keyspec); |
byte[] | createDESedeKeySpec(SecretKey key) Creates an encoded DESedeKeySpec from a SecretKey SecretKeyFactory keyfactory = SecretKeyFactory .getInstance("DESede"); DESedeKeySpec keyspec = (DESedeKeySpec) keyfactory.getKeySpec(key, DESedeKeySpec.class); return keyspec.getKey(); |
SecretKey | createSecretKey(byte[] rawkey) Creates a SecretKey from an encoded DESedeKeySpec DESedeKeySpec keyspec = new DESedeKeySpec(rawkey); SecretKeyFactory keyfactory = SecretKeyFactory .getInstance("DESede"); return keyfactory.generateSecret(keyspec); |
SecretKey | generatePBEKey(char[] password, byte[] salt, String algorthm, int iterations, int keyLength) generate PBE Key SecretKeyFactory secretKeyFactory = SecretKeyFactory .getInstance(algorthm); KeySpec keySpec = new PBEKeySpec(password, salt, iterations, keyLength); SecretKey secretKey = secretKeyFactory.generateSecret(keySpec); return secretKey; |
SecretKey | generateSymmetricKey() Generate a symmetric DES3 key. KeyGenerator symmetricKeyGenerator = KeyGenerator
.getInstance(symmetricAlgorithm);
return symmetricKeyGenerator.generateKey();
|
Cipher | getCipherFromPassphrase(String passphrase, byte[] salt, int iterations, int opMode) get Cipher From Passphrase SecretKey key = getKeyFromPassphrase(passphrase, salt, iterations); Cipher cipher = Cipher.getInstance(key.getAlgorithm()); cipher.init(opMode, key, new PBEParameterSpec(salt, iterations)); return cipher; |
Cipher | getCipherFromPassphrase(String passphrase, byte[] salt, int opMode) get Cipher From Passphrase SecretKey key = getKeyFromPassphrase(passphrase, salt); Cipher cipher = Cipher.getInstance(key.getAlgorithm()); cipher.init(opMode, key, new PBEParameterSpec(salt, 100)); return cipher; |
Mac | getMacForPassphrase(String passphrase, byte[] salt) get Mac For Passphrase SecretKey key = getKeyFromPassphrase(passphrase, salt); byte[] pbkdf2 = key.getEncoded(); SecretKeySpec hmacKey = new SecretKeySpec(pbkdf2, "HmacSHA1"); Mac hmac = Mac.getInstance("HmacSHA1"); hmac.init(hmacKey); return hmac; |
Mac | getMacForPassphrase(String passphrase, byte[] salt, int iterations) get Mac For Passphrase SecretKey key = getKeyFromPassphrase(passphrase, salt, iterations); byte[] pbkdf2 = key.getEncoded(); SecretKeySpec hmacKey = new SecretKeySpec(pbkdf2, "HmacSHA1"); Mac hmac = Mac.getInstance("HmacSHA1"); hmac.init(hmacKey); return hmac; |