Java Utililty Methods Key Pair Create

List of utility methods to do Key Pair Create

Description

The list of methods to do Key Pair Create are organized into topic(s).

Method

KeyPairgenerateKeyPair()
Create new public & private keys with length 4096.
return generateKeyPair(DEFAULT_KEY_LENGTH);
KeyPairgenerateKeyPair()
generate Key Pair
try {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ASYM_ALGORITHM);
    SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
    keyGen.initialize(512, random);
    return keyGen.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException("No such algorithm:" + e.getMessage());
KeyPairgenerateKeyPair()
generate Key Pair
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(1024, new SecureRandom());
return kpGen.generateKeyPair();
voidgenerateKeyPair()
generate Key Pair
try {
    KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
    SecureRandom random = new SecureRandom();
    random.setSeed(System.currentTimeMillis());
    generator.initialize(1024, random);
    KeyPair keyPair = generator.generateKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
...
KeyPairgenerateKeyPair()
generate Key Pair
KeyPairGenerator keyPairGenerator = null;
try {
    keyPairGenerator = KeyPairGenerator.getInstance(ALGORITHM);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
keyPairGenerator.initialize(KEYSIZE);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
...
KeyPairgenerateKeyPair()
Generate a random key pair.
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024, random);
return keyGen.generateKeyPair();
KeyPairgenerateKeyPair()
generate Key Pair
final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC");
final SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
keyPairGenerator.initialize(256, random);
final KeyPair keyPair = keyPairGenerator.generateKeyPair();
return keyPair;
KeyPairgenerateKeyPair()
Generates key-pair with KeyUtils#DEFAULT_KEY_ALGORITHM algorithm and KeyUtils#DEFAULT_KEY_SIZE key size.
return generateKeyPair(DEFAULT_KEY_ALGORITHM, DEFAULT_KEY_SIZE);
KeyPairgenerateKeyPair()
generate Key Pair
try {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(2048);
    KeyPair kp = keyGen.genKeyPair();
    return kp;
} catch (Exception e) {
    throw new RuntimeException(e);
KeyPairgenerateKeyPair()
Generates a keypair (public and private) based on Elliptic curves.
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1");
KeyPairGenerator g;
try {
    g = KeyPairGenerator.getInstance("ECDSA", BC_PROVIDER_NAME);
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
    throw new RuntimeException(e.getMessage(), e);
try {
...