Here you can find the source of generateRSAKeyPair(final int bits)
Parameter | Description |
---|---|
bits | how many bits. Must be a valid RSA size. |
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
public static KeyPair generateRSAKeyPair(final int bits) throws NoSuchAlgorithmException
//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(); } }