Here you can find the source of generateKeyPair(int size)
Parameter | Description |
---|---|
size | is the size in bits of the to be generated key. |
public static KeyPair generateKeyPair(int size)
//package com.java2s; //License from project: Open Source License import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; public class Main { private static final String RSA_ALGORITHM_NAME = "RSA"; /**//from ww w . jav a2 s. c o m * This method generates a key pair for RSA encryption. * * @param size * is the size in bits of the to be generated key. * @return A {@link KeyPair} is returned created with the given size. */ public static KeyPair generateKeyPair(int size) { try { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(RSA_ALGORITHM_NAME); keyPairGenerator.initialize(size); return keyPairGenerator.genKeyPair(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Could not generate RSA key pair!", e); } } }