public KeyPair generateKeyPair() throws KeyStoreException {
  KeyPair keyPair;
  try {
    KeyPairGenerator generator=KeyPairGenerator.getInstance("RSA");
    generator.initialize(2048);
    keyPair=generator.generateKeyPair();
  }
 catch (  NoSuchAlgorithmException e) {
    throw new KeyStoreException("Unable to generate PKI",e);
  }
  return keyPair;
}

public KeyPair generateKeyPair ( ) throws KeyStoreException { KeyPair keyPair ; try { KeyPairGenerator generator = KeyPairGenerator . getInstance ( "RSA" ) ; generator . initialize ( 2048 ) ; keyPair = generator . generateKeyPair ( ) ; } catch ( NoSuchAlgorithmException e ) { throw new KeyStoreException ( "Unable to generate PKI" , e ) ; } return keyPair ; }
generates a pki ( a public and private key for rsa )
