Example usage for java.security AlgorithmParameterGenerator init

List of usage examples for java.security AlgorithmParameterGenerator init

Introduction

In this page you can find the example usage for java.security AlgorithmParameterGenerator init.

Prototype

public final void init(AlgorithmParameterSpec genParamSpec) throws InvalidAlgorithmParameterException 

Source Link

Document

Initializes this parameter generator with a set of algorithm-specific parameter generation values.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
    paramGen.init(1024);

    AlgorithmParameters params = paramGen.generateParameters();
    DHParameterSpec dhSpec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class);

    System.out.println("" + dhSpec.getP() + "," + dhSpec.getG() + "," + dhSpec.getL());
}

From source file:SecureConnection.java

public byte[] getPublicKey(int size) throws Exception {
    AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
    paramGen.init(size);
    AlgorithmParameters params = paramGen.generateParameters();
    DHParameterSpec dhParamSpec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class);
    return this.getPublicKeyStep2(dhParamSpec);
}

From source file:hudson.cli.Connection.java

public KeyAgreement diffieHellman(boolean side, int keySize) throws IOException, GeneralSecurityException {
    KeyPair keyPair;/*from w ww .j a  v a  2s  . c o  m*/
    PublicKey otherHalf;

    if (side) {
        AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
        paramGen.init(keySize);

        KeyPairGenerator dh = KeyPairGenerator.getInstance("DH");
        dh.initialize(paramGen.generateParameters().getParameterSpec(DHParameterSpec.class));
        keyPair = dh.generateKeyPair();

        // send a half and get a half
        writeKey(keyPair.getPublic());
        otherHalf = KeyFactory.getInstance("DH").generatePublic(readKey());
    } else {
        otherHalf = KeyFactory.getInstance("DH").generatePublic(readKey());

        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("DH");
        keyPairGen.initialize(((DHPublicKey) otherHalf).getParams());
        keyPair = keyPairGen.generateKeyPair();

        // send a half and get a half
        writeKey(keyPair.getPublic());
    }

    KeyAgreement ka = KeyAgreement.getInstance("DH");
    ka.init(keyPair.getPrivate());
    ka.doPhase(otherHalf, true);

    return ka;
}

From source file:org.apache.abdera2.common.security.DHBase.java

private void init() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
        InvalidParameterSpecException, InvalidKeySpecException {
    AlgorithmParameterGenerator pgen = AlgorithmParameterGenerator.getInstance("DH");
    pgen.init(512);
    AlgorithmParameters params = pgen.generateParameters();
    DHParameterSpec dhspec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class);
    KeyPairGenerator keypairgen = KeyPairGenerator.getInstance("DH");
    keypairgen.initialize(dhspec);/*from www . j  av a2 s. c o  m*/
    keyPair = keypairgen.generateKeyPair();
    p = dhspec.getP();
    g = dhspec.getG();
    l = dhspec.getL();
}

From source file:org.jenkinsci.plugins.relution_publisher.configuration.jobs.ArtifactPublisher.java

private void testDHKeypairSize(final Log log, final int sizeBits) {
    try {//  www  .  j  av a2  s  .c  om
        final AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DiffieHellman");
        apg.init(sizeBits);
        log.write(this, "DH keypair with %,d bits is supported", sizeBits);
    } catch (final Exception e) {
        log.write(this, "DH keypair with %,d bits is UNSUPPORTED", sizeBits);
    }
}