List of utility methods to do RSA
Map | generateKeys() generate Keys KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2048); KeyPair kp = keyGen.genKeyPair(); byte[] publicKey = kp.getPublic().getEncoded(); byte[] privateKey = kp.getPrivate().getEncoded(); Base64.Encoder encoder = Base64.getEncoder(); String publicRSA = "-----BEGIN PUBLIC KEY-----\n" + encoder.encodeToString(privateKey) + "\n-----END PUBLIC KEY-----\n"; ... |
KeyPair | generateRSA(int keySize) generate RSA KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC"); g.initialize(keySize, new SecureRandom()); return g.generateKeyPair(); |
KeyPair | generateRSAKey(int keySize) Generates a new RSA key with specified keySize try { KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); generator.initialize(keySize); return generator.genKeyPair(); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); |
KeyPair | generateRSAKeyPair() Create a random 1024 bit RSA key pair KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC"); kpGen.initialize(1024, new SecureRandom()); return kpGen.generateKeyPair(); |
KeyPair | generateRSAKeyPair() generate RSA Key Pair try { KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA"); keyGenerator.initialize(1024); return keyGenerator.genKeyPair(); } catch (Exception ex) { return null; |
KeyPair | generateRsaKeyPair() Generates a new RSA key pair. KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA"); KeyPair kp = kg.generateKeyPair(); return kp; |
KeyPair | generateRSAKeyPair() generate RSA Key Pair try { KeyPairGenerator kpg = KeyPairGenerator.getInstance(RSA_ALGORITHM_KEY); kpg.initialize(2048); KeyPair keyPair = kpg.genKeyPair(); return keyPair; } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Unknown encryption algorithm provided: " + RSA_ALGORITHM_KEY, e); |
KeyPair | generateRSAKeyPair(final int bits) Generate a new asymmetric encryption key pair. KeyPairGenerator gen = KeyPairGenerator.getInstance(RSA_ALGORITHM);
gen.initialize(bits);
return gen.generateKeyPair();
|
KeyPair | generateRSAKeypair(final int keysize, BigInteger publicExponent) generate RSA Keypair KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC"); if (publicExponent == null) { publicExponent = RSAKeyGenParameterSpec.F4; AlgorithmParameterSpec params = new RSAKeyGenParameterSpec(keysize, publicExponent); kpGen.initialize(params); return kpGen.generateKeyPair(); |
KeyPair | generateRSAKeyPair(int bitsize) generate RSA Key Pair KeyPair keypair = null; try { KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(bitsize); keypair = kpg.genKeyPair(); } catch (Exception ex) { ex.printStackTrace(); return keypair; |