Example usage for java.security KeyPairGenerator getInstance

List of usage examples for java.security KeyPairGenerator getInstance

Introduction

In this page you can find the example usage for java.security KeyPairGenerator getInstance.

Prototype

public static KeyPairGenerator getInstance(String algorithm, Provider provider)
        throws NoSuchAlgorithmException 

Source Link

Document

Returns a KeyPairGenerator object that generates public/private key pairs for the specified algorithm.

Usage

From source file:com.iterzp.momo.utils.RSAUtils.java

/**
 * ?//from  w ww  .j  a  v a 2 s  . c o m
 * 
 * @return 
 */
public static KeyPair generateKeyPair() {
    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", PROVIDER);
        keyPairGenerator.initialize(KEY_SIZE, new SecureRandom());
        return keyPairGenerator.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
private static void generateNewKey() {
    try {// www.ja  v a2 s. c  o m
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
                KEY_PROVIDER);

        keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(KEY_ALIAS, KeyProperties.PURPOSE_DECRYPT)
                .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP).build());
        keyPairGenerator.generateKeyPair();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static KeyPair genKeyPair() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException,
        NoSuchProviderException, InvalidKeyException, SignatureException {
    KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA", "BC");
    keyPairGen.initialize(1024, new SecureRandom());
    KeyPair keypair = keyPairGen.genKeyPair();
    return keypair;
}

From source file:MainClass.java

public static KeyPair generateRSAKeyPair() throws Exception {
    KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
    kpGen.initialize(1024, new SecureRandom());
    return kpGen.generateKeyPair();
}

From source file:com.google.jenkins.plugins.credentials.oauth.P12ServiceAccountConfigTestUtil.java

public static KeyPair generateKeyPair() throws NoSuchProviderException, NoSuchAlgorithmException {
    Security.addProvider(new BouncyCastleProvider());
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
    keyPairGenerator.initialize(1024);/* w ww .j  a  v  a  2s .  c o m*/
    return keyPairGenerator.generateKeyPair();
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * ?/*from   w  ww .j  a  v a2  s.  c om*/
 * 
 * @param keySize
 *            ?
 * @return 
 */
public static KeyPair generateKeyPair(int keySize) {
    Assert.state(keySize > 0);

    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM, PROVIDER);
        keyPairGenerator.initialize(keySize);
        return keyPairGenerator.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.globus.gsi.bc.BouncyCastleOpenSSLKeyTest.java

private KeyPair getKeyPair() throws Exception {
    CertUtil.init();//from  w ww.ja  v  a  2s  .co  m

    int bits = 512;

    KeyPairGenerator keyGen = null;
    keyGen = KeyPairGenerator.getInstance("RSA", "BC");
    keyGen.initialize(bits);

    return keyGen.genKeyPair();
}

From source file:com.aqnote.shared.cryptology.asymmetric.DSA.java

public static KeyPair genKeyPair(int bit) {
    try {/*from ww  w .  j av a 2 s .c  o  m*/
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(ALGORITHM, JCE_PROVIDER);
        keyPairGen.initialize(bit, new SecureRandom());
        return keyPairGen.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.ebayopensource.fido.uaf.crypto.KeyCodec.java

public static KeyPair getKeyPair()
        throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
    //ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("prime192v1");
    ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp256r1");
    KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "SC");
    g.initialize(ecGenSpec, new SecureRandom());
    return g.generateKeyPair();
}

From source file:com.microsoft.azure.keyvault.cryptography.RsaKey.java

public RsaKey(String kid, int keySize, Provider provider) throws NoSuchAlgorithmException {

    if (Strings.isNullOrWhiteSpace(kid)) {
        throw new IllegalArgumentException("kid");
    }//from  w  ww  . j  a  v  a 2 s . c om

    final KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", provider);

    generator.initialize(keySize);

    _kid = kid;
    _keyPair = generator.generateKeyPair();
    _provider = provider;
}