Android AES Key Get createKey(String password)

Here you can find the source of createKey(String password)

Description

create Key

Declaration

private static SecretKeySpec createKey(String password) 

Method Source Code

//package com.java2s;
import java.io.UnsupportedEncodingException;

import javax.crypto.spec.SecretKeySpec;

public class Main {

    private static SecretKeySpec createKey(String password) {
        byte[] data = null;
        if (password == null) {
            password = "";
        }//w w  w  . j  a va  2  s  . c o  m
        StringBuffer sb = new StringBuffer(32);
        sb.append(password);
        while (sb.length() < 32) {
            sb.append("0");
        }
        if (sb.length() > 32) {
            sb.setLength(32);
        }

        try {
            data = sb.toString().getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return new SecretKeySpec(data, "AES");
    }
}

Related

  1. getKeyBytes(String key)
  2. getRawKey(String key)
  3. getRawKey(byte[] seed)
  4. getRawKey(byte[] seed)