public void generateKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException {
  KeyPairGenerator keyPairGenerator=KeyPairGenerator.getInstance("RSA","BC");
  if (keySize < 512) {
    keySize=512;
  }
  keyPairGenerator.initialize(keySize,new SecureRandom());
  KeyPair keyPair=keyPairGenerator.generateKeyPair();
  privateKey=keyPair.getPrivate();
  publicKey=keyPair.getPublic();
}

public void generateKeyPair ( ) throws NoSuchAlgorithmException , NoSuchProviderException , InvalidKeySpecException { KeyPairGenerator keyPairGenerator = KeyPairGenerator . getInstance ( "RSA" , "BC" ) ; if ( keySize < 512 ) { keySize = 512 ; } keyPairGenerator . initialize ( keySize , new SecureRandom ( ) ) ; KeyPair keyPair = keyPairGenerator . generateKeyPair ( ) ; privateKey = keyPair . getPrivate ( ) ; publicKey = keyPair . getPublic ( ) ; }
generates a public and private key with the minimum size of 512 bytes and set the variables of this object .
