Android Key Create generateKey(byte[] randomSeed)

Here you can find the source of generateKey(byte[] randomSeed)

Description

generate Key

Declaration

public static byte[] generateKey(byte[] randomSeed) throws Exception 

Method Source Code

//package com.java2s;
import java.security.SecureRandom;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class Main {
    private static final String CIPHER_ALGORITHM = "AES";
    private static final String RANDOM_GENERATOR_TYPE = "SHA1PRNG";
    private static final int RANDOM_KEY_SIZE = 128;

    public static byte[] generateKey(byte[] randomSeed) throws Exception {
        // Set up generators
        KeyGenerator gen = KeyGenerator.getInstance(CIPHER_ALGORITHM);
        SecureRandom rand = SecureRandom.getInstance(RANDOM_GENERATOR_TYPE);
        rand.setSeed(randomSeed);//from w  ww . j a v  a  2s .co m

        // Generate key
        gen.init(RANDOM_KEY_SIZE, rand);
        SecretKey myKey = gen.generateKey();

        return myKey.getEncoded();
    }
}

Related

  1. generateKey(String key)
  2. getRawKey(byte[] seed)
  3. getRawKey(byte[] seed)
  4. createRandomKey(int size)
  5. generateKey(byte[] seed)