Java RSA generateRSAKeyPair(final int bits)

Here you can find the source of generateRSAKeyPair(final int bits)

Description

Generate a new asymmetric encryption key pair.

License

Open Source License

Parameter

Parameter Description
bits how many bits. Must be a valid RSA size.

Exception

Parameter Description
NoSuchAlgorithmException an exception

Return

generated RSA key pair.

Declaration

public static KeyPair generateRSAKeyPair(final int bits) throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.KeyPair;
import java.security.KeyPairGenerator;

import java.security.NoSuchAlgorithmException;

public class Main {
    /** Algorithm used by RSA keys and ciphers. */
    public static final String RSA_ALGORITHM = "RSA";

    /**/*w ww . j  a  v  a 2  s.  c  om*/
     * Generate a new asymmetric encryption key pair.
     *
     * @param bits
     *            how many bits. Must be a valid RSA size.
     * @return generated RSA key pair.
     * @throws NoSuchAlgorithmException
     */
    public static KeyPair generateRSAKeyPair(final int bits) throws NoSuchAlgorithmException {
        KeyPairGenerator gen = KeyPairGenerator.getInstance(RSA_ALGORITHM);
        gen.initialize(bits);
        return gen.generateKeyPair();
    }
}

Related

  1. generateRSAKey(int keySize)
  2. generateRSAKeyPair()
  3. generateRSAKeyPair()
  4. generateRsaKeyPair()
  5. generateRSAKeyPair()
  6. generateRSAKeypair(final int keysize, BigInteger publicExponent)
  7. generateRSAKeyPair(int bitsize)
  8. generateRsaKeyPair(int keysize)
  9. generateRSAKeypairAndKeystore(String fullyQualifiedDN, Date endDate, String keystoreLocation, String keyPairAlias, String keypairPassword, String keystorePassword)