Java Key Pair Create generateKey()

Here you can find the source of generateKey()

Description

generate Key

License

Open Source License

Declaration

public static String generateKey() throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.SecureRandom;
import java.util.Base64;

import javax.crypto.KeyGenerator;

import javax.crypto.SecretKey;

public class Main {
    private static final int KEY_SIZE_IN_BITS = 128;

    public static String generateKey() throws Exception {
        SecureRandom random = SecureRandom.getInstanceStrong();
        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        keyGen.init(KEY_SIZE_IN_BITS, random);
        SecretKey key = keyGen.generateKey();

        return new String(Base64.getEncoder().encode(key.getEncoded()), "UTF-8");
    }/* w w  w.jav  a2  s .  c o  m*/
}

Related

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