Android AES Key Get initSecretKey()

Here you can find the source of initSecretKey()

Description

init secret key

Exception

Parameter Description
Exception an exception

Return

byte[] secret key

Declaration

public static byte[] initSecretKey() 

Method Source Code

//package com.java2s;

import java.security.NoSuchAlgorithmException;

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

public class Main {
    /**//  ww  w.  ja  va2  s .c  o m
     * Secret Key algorithms
     */
    private static final String KEY_ALGORITHM = "AES";

    /**
     * init secret key
     *
     * @return byte[] secret key
     * @throws Exception
     */
    public static byte[] initSecretKey() {
        KeyGenerator kg = null;
        try {
            kg = KeyGenerator.getInstance(KEY_ALGORITHM);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return new byte[0];
        }
        //init secret key generator and set size.
        //AES key length is 128
        kg.init(128);
        //create a secret key
        SecretKey secretKey = kg.generateKey();
        return secretKey.getEncoded();
    }
}

Related

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