List of usage examples for java.security KeyPairGenerator initialize
public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException
From source file:org.artifactory.security.crypto.CryptoHelper.java
public static KeyPair generateKeyPair() { try {//from w w w . j a va 2 s . c o m 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()); } }
From source file:com.peterphi.std.crypto.keygen.CaHelper.java
public static KeyPair generateKeyPair(int bits) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC"); keyGen.initialize(bits, new SecureRandom()); return keyGen.generateKeyPair(); }
From source file:test.integ.be.fedict.commons.eid.client.SSLTest.java
private static KeyPair generateKeyPair() throws Exception { final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); final SecureRandom random = new SecureRandom(); keyPairGenerator.initialize(new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4), random); final KeyPair keyPair = keyPairGenerator.generateKeyPair(); return keyPair; }
From source file:Main.java
/** * Generates a public/private key pair that meets Thali's security requirements * @return// ww w. j a v a 2s . c o m */ public static KeyPair GenerateThaliAcceptablePublicPrivateKeyPair() { KeyPairGenerator keyPairGenerator = null; try { keyPairGenerator = KeyPairGenerator.getInstance(KeyTypeIdentifier); // TODO: http://android-developers.blogspot.com/2013/08/some-securerandom-thoughts.html talks about security // failures in Android caused by improperly initialized RNGs. It would appear that this issue doesn't // apply to the latest version of Android. But obviously this is something that has to be further investigated // to make sure we are doing this correctly. keyPairGenerator.initialize(KeySizeInBits, new SecureRandom()); return keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.aon.esolutions.appconfig.client.util.RSAEncryptUtil.java
/** * Generate key which contains a pair of privae and public key using 1024 bytes * @return key pair/*from ww w. j a va 2s .co m*/ * @throws NoSuchAlgorithmException */ public static KeyPair generateKey(String keyPhrase) throws GeneralSecurityException { KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM); SecureRandom randomAlg = SecureRandom.getInstance("SHA1PRNG", "SUN"); randomAlg.setSeed(keyPhrase.getBytes()); keyGen.initialize(1024, randomAlg); KeyPair key = keyGen.generateKeyPair(); return key; }
From source file:net.link.util.common.KeyUtils.java
public static KeyPair generateKeyPair(String algorithm) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm); SecureRandom random = new SecureRandom(); if ("RSA".equals(keyPairGenerator.getAlgorithm())) try {// ww w . j av a 2 s . co m keyPairGenerator.initialize(new RSAKeyGenParameterSpec(RSA_KEYSIZE, RSAKeyGenParameterSpec.F4), random); } catch (InvalidAlgorithmParameterException e) { throw new InternalInconsistencyException("KeyGenParams incompatible with key generator.", e); } else if (keyPairGenerator instanceof DSAKeyPairGenerator) { DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator; dsaKeyPairGenerator.initialize(DSA_MODLEN, false, random); } return keyPairGenerator.generateKeyPair(); }
From source file:com.owncloud.android.utils.EncryptionUtils.java
public static KeyPair generateKeyPair() throws NoSuchAlgorithmException { KeyPairGenerator keyGen = KeyPairGenerator.getInstance(RSA); keyGen.initialize(2048, new SecureRandom()); return keyGen.generateKeyPair(); }
From source file:test.integ.be.fedict.trust.util.TestUtils.java
public static KeyPair generateKeyPair(String algorithm) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm); SecureRandom random = new SecureRandom(); if ("RSA".equals(keyPairGenerator.getAlgorithm())) { keyPairGenerator.initialize(new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4), random); } else if (keyPairGenerator instanceof DSAKeyPairGenerator) { DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator; dsaKeyPairGenerator.initialize(512, false, random); }/*from w w w . ja v a 2s . c om*/ return keyPairGenerator.generateKeyPair(); }
From source file:org.xdi.oxauth.model.util.JwtUtil.java
public static KeyPair generateRsaKey() throws NoSuchAlgorithmException, NoSuchProviderException { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC"); keyGen.initialize(2048, new SecureRandom()); return keyGen.generateKeyPair(); }
From source file:org.xdi.oxauth.model.util.JwtUtil.java
public static KeyPair generateKeyES256() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("P-256"); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "BC"); keyGen.initialize(ecSpec, new SecureRandom()); return keyGen.generateKeyPair(); }