Here you can find the source of initSecretKey()
Parameter | Description |
---|---|
Exception | an exception |
public static byte[] initSecretKey()
//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(); } }