Android AES Key Get makeKey(String passkey)

Here you can find the source of makeKey(String passkey)

Description

make Key

Declaration

static Key makeKey(String passkey) 

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);
    }/*  w  ww .ja  v  a  2 s .com*/

    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. getSecretKey(String key)
  3. initSecretKey()
  4. keyAreEqual(byte[] b1, byte[] b2)
  5. makeKey()
  6. toKey(byte[] key)
  7. generateEncryptionSecret()