List of utility methods to do Key Pair Create
void | generateKeyPair(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)); ... |
KeyPair | generateKeyPair(int keySizeInBits, String algo) generate Key Pair KeyPairGenerator kg = KeyPairGenerator.getInstance(algo);
kg.initialize(keySizeInBits);
return kg.generateKeyPair();
|
KeyPair | generateKeyPair(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(); ... |
KeyPair | generateKeyPair(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); |
KeyPair | generateKeyPair(String algo) generate Key Pair KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo);
return kpg.genKeyPair();
|
KeyPair | generateKeyPair(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(); ... |
KeyPair | generateKeyPair(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(); ... |
KeyPair | generateKeyPair(String algorithm, int keySize) generate Key Pair return createKeyPairGenerator(algorithm, keySize).generateKeyPair();
|
KeyPair | generateKeyPair(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(); ... |
KeyPair | generateKeyPair(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); ... |