Java Key Pair Create generateKeyPair(int keySize)

Here you can find the source of generateKeyPair(int keySize)

Description

generate Key Pair

License

LGPL

Declaration

public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException, NoSuchProviderException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

import java.security.SecureRandom;

public class Main {
    private static final String KEYGEN_ALGORITHM = "RSA";
    private static final String SECURE_RANDOM_ALGORITHM = "SHA1PRNG";

    public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException, NoSuchProviderException {
        KeyPairGenerator generator = KeyPairGenerator.getInstance(KEYGEN_ALGORITHM/* , PROVIDER_NAME */);
        SecureRandom secureRandom = SecureRandom.getInstance(SECURE_RANDOM_ALGORITHM/* , PROVIDER_NAME */);
        generator.initialize(keySize, secureRandom);
        return generator.generateKeyPair();
    }// ww  w .jav a2 s.  c  o m
}

Related

  1. generateKeyPair()
  2. generateKeyPair(final Provider provider, final String keyPairAlgorithm, final String secureAlgorithm)
  3. generateKeyPair(final String algorithm, final int keylen)
  4. generateKeyPair(final String algorithmModePad, final int keySize)
  5. generateKeyPair(int bit)
  6. generateKeyPair(int keySize)
  7. generateKeyPair(int keySize)
  8. generateKeyPair(int keySize)
  9. generateKeyPair(int keysize)