Android Utililty Methods Key Create

List of utility methods to do Key Create

Description

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

Method

SecretKeygetKeyFromPassphrase(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);
SecretKeygetKeyFromPassphrase(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();
SecretKeycreateSecretKey(byte[] rawkey)
Creates a SecretKey from an encoded DESedeKeySpec
DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
SecretKeyFactory keyfactory = SecretKeyFactory
        .getInstance("DESede");
return keyfactory.generateSecret(keyspec);
SecretKeygeneratePBEKey(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;
SecretKeygenerateSymmetricKey()
Generate a symmetric DES3 key.
KeyGenerator symmetricKeyGenerator = KeyGenerator
        .getInstance(symmetricAlgorithm);
return symmetricKeyGenerator.generateKey();
CiphergetCipherFromPassphrase(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;
CiphergetCipherFromPassphrase(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;
MacgetMacForPassphrase(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;
MacgetMacForPassphrase(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;