Here you can find the source of generateKeyPair()
public static KeyPair generateKeyPair()
//package com.java2s; //License from project: Open Source License import java.security.*; public class Main { private static final String ALGORITHM = "RSA"; private static final int KEYSIZE = 1024; public static KeyPair generateKeyPair() { KeyPairGenerator keyPairGenerator = null; try {/*from ww w . j av a 2 s.com*/ keyPairGenerator = KeyPairGenerator.getInstance(ALGORITHM); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } keyPairGenerator.initialize(KEYSIZE); KeyPair keyPair = keyPairGenerator.generateKeyPair(); return keyPair; } }