Here you can find the source of generateKey()
Parameter | Description |
---|---|
GeneralSecurityException | the general security exception |
public static byte[] generateKey() throws GeneralSecurityException
//package com.java2s; //License from project: Apache License import java.security.GeneralSecurityException; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class Main { /** The Constant KEY_ALGORITHM. */ private static final String KEY_ALGORITHM = "AES"; /**//from w w w .j av a 2 s . c o m * Generate key. * * @return the byte[] * @throws GeneralSecurityException the general security exception */ public static byte[] generateKey() throws GeneralSecurityException { KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM); // java max 128 keyGenerator.init(128); SecretKey secretKey = keyGenerator.generateKey(); return secretKey.getEncoded(); } }