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

voidgenerateKeyPair(int keySize, String fileChavePublica, String fileChavePrivada)
generate Key Pair
KeyPairGenerator pairgen = KeyPairGenerator.getInstance("RSA");
SecureRandom random = new SecureRandom();
pairgen.initialize(keySize, random);
KeyPair keyPair = pairgen.generateKeyPair();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(fileChavePublica));
out.writeObject(keyPair.getPublic());
out.close();
out = new ObjectOutputStream(new FileOutputStream(fileChavePrivada));
...
KeyPairgenerateKeyPair(int keySizeInBits, String algo)
generate Key Pair
KeyPairGenerator kg = KeyPairGenerator.getInstance(algo);
kg.initialize(keySizeInBits);
return kg.generateKeyPair();
KeyPairgenerateKeyPair(int len)
generate Key Pair
KeyPairGenerator kpGen;
try {
    kpGen = KeyPairGenerator.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
    throw new IllegalStateException("RSA algorithm not supported!?", e);
kpGen.initialize(len, new SecureRandom());
return kpGen.generateKeyPair();
...
KeyPairgenerateKeyPair(int size)
This method generates a key pair for RSA encryption.
try {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(RSA_ALGORITHM_NAME);
    keyPairGenerator.initialize(size);
    return keyPairGenerator.genKeyPair();
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("Could not generate RSA key pair!", e);
KeyPairgenerateKeyPair(String algo)
generate Key Pair
KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo);
return kpg.genKeyPair();
KeyPairgenerateKeyPair(String algo, int keyLength, String provider)
Generate a random asymmetric key pair.
KeyPairGenerator keyGenerator = null;
if (provider != null) {
    keyGenerator = KeyPairGenerator.getInstance(algo, provider);
} else {
    keyGenerator = KeyPairGenerator.getInstance(algo);
keyGenerator.initialize(keyLength);
return keyGenerator.generateKeyPair();
...
KeyPairgenerateKeyPair(String algorithm, int bits)
Generates a key pair of given algorithm and strength.
KeyPairGenerator generator = null;
if (provider == null) {
    generator = KeyPairGenerator.getInstance(algorithm);
} else {
    generator = KeyPairGenerator.getInstance(algorithm, provider);
generator.initialize(bits);
return generator.generateKeyPair();
...
KeyPairgenerateKeyPair(String algorithm, int keySize)
generate Key Pair
return createKeyPairGenerator(algorithm, keySize).generateKeyPair();
KeyPairgenerateKeyPair(String algorithm, int keysize)
generate Key Pair
if (algorithm.equalsIgnoreCase("RSA") && keysize < 1024)
    throw new IllegalArgumentException("key size should be 1024 or higher");
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(algorithm);
SecureRandom rnd = null;
try {
    rnd = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException e) {
    rnd = new SecureRandom();
...
KeyPairgenerateKeyPair(String algorithm, int size)
generate Key Pair
KeyPairGenerator keyGen = null;
try {
    keyGen = KeyPairGenerator.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
    throw new KeyException("Cannot initialize keypair generator", e);
SecureRandom random = new SecureRandom();
keyGen.initialize(size, random);
...