Java Key Pair Create generateKey()

Here you can find the source of generateKey()

Description

Generate key.

License

Apache License

Exception

Parameter Description
GeneralSecurityException the general security exception

Return

the byte[]

Declaration

public static byte[] generateKey() throws GeneralSecurityException 

Method Source Code

//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();
    }
}

Related

  1. generateKey()
  2. generateKey()
  3. generateKey()
  4. generateKey()