Android AES Key Get getSecretKey(String key)

Here you can find the source of getSecretKey(String key)

Description

get Secret Key

Declaration

private static SecretKeySpec getSecretKey(String key) 

Method Source Code

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

import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static final String UTF_8 = "UTF-8";

    private static SecretKeySpec getSecretKey(String key) {
        MessageDigest digest;/*from   w ww  . j a va2s  .  co  m*/
        try {
            digest = MessageDigest.getInstance("md5");
            SecretKeySpec keySpec = new SecretKeySpec(digest.digest(key
                    .getBytes(UTF_8)), "AES");
            return keySpec;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

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