Here you can find the source of generateKeyPair(String algorithm, int keysize)
public static KeyPair generateKeyPair(String algorithm, int keysize) throws NoSuchAlgorithmException
//package com.java2s; //License from project: Open Source License import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; public class Main { public static KeyPair generateKeyPair(String algorithm, int keysize) throws NoSuchAlgorithmException { if (algorithm.equalsIgnoreCase("RSA") && keysize < 1024) throw new IllegalArgumentException("key size should be 1024 or higher"); KeyPairGenerator keyGen = KeyPairGenerator.getInstance(algorithm); SecureRandom rnd = null;/*from w ww.java 2 s. c om*/ try { rnd = SecureRandom.getInstanceStrong(); } catch (NoSuchAlgorithmException e) { rnd = new SecureRandom(); } keyGen.initialize(keysize, rnd); KeyPair pair = keyGen.generateKeyPair(); return pair; } public static KeyPair generateKeyPair() throws NoSuchAlgorithmException { return generateKeyPair(1.0); } public static KeyPair generateKeyPair(double multiplier) throws NoSuchAlgorithmException { return generateKeyPair("RSA", (int) (4096 * multiplier)); } }