Example usage for java.security KeyPairGenerator getAlgorithm

List of usage examples for java.security KeyPairGenerator getAlgorithm

Introduction

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

Prototype

public String getAlgorithm() 

Source Link

Document

Returns the standard name of the algorithm for this key pair generator.

Usage

From source file:net.link.util.test.pkix.PkiTestUtils.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(RSA_KEYSIZE, RSAKeyGenParameterSpec.F4), random);
    else if (keyPairGenerator instanceof DSAKeyPairGenerator) {
        DSAKeyPairGenerator dsaKeyPairGenerator = (DSAKeyPairGenerator) keyPairGenerator;
        dsaKeyPairGenerator.initialize(DSA_MODLEN, false, random);
    }//from   www. ja  v  a  2s  . c  o  m
    return keyPairGenerator.generateKeyPair();
}

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 {/* w  ww .  j  a v  a2  s . c om*/
            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: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  ww  . jav a  2 s  .c o  m
    return keyPairGenerator.generateKeyPair();
}