Java Key Pair Create generateKeyPair()

Here you can find the source of generateKeyPair()

Description

Generate key which contains a pair of private and public key using 1024 bytes

License

Apache License

Exception

Parameter Description
NoSuchAlgorithmException an exception

Return

key pair

Declaration

public static KeyPair generateKeyPair() throws NoSuchAlgorithmException 

Method Source Code

//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;
    }
}

Related

  1. generateKeyAES()
  2. generateKeyDigest(int keyLength, String password)
  3. generateKeyFromString(final String secKey, String algorithm)
  4. generateKeyPair()
  5. generateKeyPair()
  6. generateKeyPair()
  7. generateKeyPair()
  8. generateKeyPair()
  9. generateKeyPair()