Android Utililty Methods AES Key Get

List of utility methods to do AES Key Get

Description

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

Method

byte[]initSecretKey()
init secret key
KeyGenerator kg = null;
try {
    kg = KeyGenerator.getInstance(KEY_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    return new byte[0];
kg.init(128);
...
booleankeyAreEqual(byte[] b1, byte[] b2)
compare if the given two keys are equal
if (b1.length != b2.length) {
    return false;
for (int i = 0; i < b1.length; i++) {
    if (b1[i] != b2[i]) {
        return false;
return true;
KeymakeKey()
make Key
return makeKey(ENCRYPTION_KEY);
KeymakeKey(String passkey)
make Key
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    byte[] key = md.digest(passkey.getBytes("UTF-8"));
    return new SecretKeySpec(key, "AES");
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
...
KeytoKey(byte[] key)
transfer secret key
return new SecretKeySpec(key, KEY_ALGORITHM);
byte[]generateEncryptionSecret()
generate Encryption Secret
try {
    KeyGenerator generator = KeyGenerator.getInstance("AES");
    generator.init(128);
    SecretKey key = generator.generateKey();
    return key.getEncoded();
} catch (NoSuchAlgorithmException ex) {
    Log.w("keyutil", ex);
    return null;
...