Android AES Key Get makeKey()

Here you can find the source of makeKey()

Description

make Key

Declaration

static Key makeKey() 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static final String ENCRYPTION_KEY = "RwcmlVpg";

    static Key makeKey() {
        return makeKey(ENCRYPTION_KEY);
    }/*from   w w  w.ja va2  s .c o m*/

    static Key makeKey(String passkey) {
        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();
        }

        return null;
    }
}

Related

  1. getRawKey(byte[] seed)
  2. getRawKey(byte[] seed)
  3. getSecretKey(String key)
  4. initSecretKey()
  5. keyAreEqual(byte[] b1, byte[] b2)
  6. makeKey(String passkey)
  7. toKey(byte[] key)
  8. generateEncryptionSecret()