Here you can find the source of generateKeyPair()
public static KeyPair generateKeyPair() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
//package com.java2s; /*//from w w w. j a va 2 s.c o m * SafeOnline project. * * Copyright 2005-2006 Frank Cornelis. * Copyright 2006-2007 Lin.k N.V. All rights reserved. * Lin.k N.V. proprietary/confidential. Use is subject to license terms. */ import java.security.*; import java.security.interfaces.DSAKeyPairGenerator; import java.security.spec.RSAKeyGenParameterSpec; public class Main { protected static final int RSA_KEYSIZE = 1024; protected static final int DSA_MODLEN = 512; public static KeyPair generateKeyPair() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { return generateKeyPair("RSA"); } public static KeyPair generateKeyPair(String algorithm) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { KeyPairGenerator keyPairGenerator = KeyPairGenerator .getInstance(algorithm); SecureRandom random = new SecureRandom(); if ("RSA".equals(keyPairGenerator.getAlgorithm())) keyPairGenerator.initialize(new RSAKeyGenParameterSpec( RSA_KEYSIZE, RSAKeyGenParameterSpec.F4), random); else if (keyPairGenerator instanceof DSAKeyPairGenerator) { DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator; dsaKeyPairGenerator.initialize(DSA_MODLEN, false, random); } return keyPairGenerator.generateKeyPair(); } }