Here you can find the source of generateKeyPair()
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
public static KeyPair generateKeyPair() throws NoSuchAlgorithmException
//package com.java2s; //License from project: Apache License import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; public class Main { private static final String ALGORITHM = "RSA"; private static final int keyLength = 1024; /**//ww w . ja v a 2 s . co m * Generate key which contains a pair of private and public key using 1024 bytes * @return key pair * @throws NoSuchAlgorithmException */ public static KeyPair generateKeyPair() throws NoSuchAlgorithmException { KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM); keyGen.initialize(keyLength); KeyPair keyPair = keyGen.generateKeyPair(); return keyPair; } }