Here you can find the source of generateKeyPair()
public static KeyPair generateKeyPair() throws Exception
//package com.java2s; //License from project: Open Source License import java.security.*; public class Main { private static KeyPairGenerator generator; public static KeyPair generateKeyPair() throws Exception { if (generator == null) { generator = KeyPairGenerator.getInstance("RSA"); }/* w w w. ja va 2s . c om*/ generator.initialize(2048); return generator.genKeyPair(); } }