Example usage for javax.crypto.spec DHParameterSpec DHParameterSpec

List of usage examples for javax.crypto.spec DHParameterSpec DHParameterSpec

Introduction

In this page you can find the example usage for javax.crypto.spec DHParameterSpec DHParameterSpec.

Prototype

public DHParameterSpec(BigInteger p, BigInteger g, int l) 

Source Link

Document

Constructs a parameter set for Diffie-Hellman, using a prime modulus p, a base generator g, and the size in bits, l, of the random exponent (private value).

Usage

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

private void init(BigInteger p, BigInteger g, int l, byte[] key)
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException {
    DHParameterSpec spec = new DHParameterSpec(p, g, l);
    KeyPairGenerator keypairgen = KeyPairGenerator.getInstance("DH");
    keypairgen.initialize(spec);/*from   ww w .  ja v a2s  . co  m*/
    keyPair = keypairgen.generateKeyPair();
    publicKey = decode(key);
}

From source file:org.apache.geode.internal.cache.tier.sockets.HandShake.java

/**
 * Initialize the Diffie-Hellman keys. This method is not thread safe
 *//*  w w w.  j a v  a  2  s .  c om*/
public static void initDHKeys(DistributionConfig config) throws Exception {

    dhSKAlgo = config.getSecurityClientDHAlgo();
    dhPrivateKey = null;
    dhPublicKey = null;
    // Initialize the keys when either the host is a client that has
    // non-blank setting for DH symmetric algo, or this is a server
    // that has authenticator defined.
    if ((dhSKAlgo != null && dhSKAlgo.length() > 0) /* || securityService.isClientSecurityRequired() */) {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
        DHParameterSpec dhSpec = new DHParameterSpec(dhP, dhG, dhL);
        keyGen.initialize(dhSpec);
        KeyPair keypair = keyGen.generateKeyPair();

        // Get the generated public and private keys
        dhPrivateKey = keypair.getPrivate();
        dhPublicKey = keypair.getPublic();

        random = new SecureRandom();
        // Force the random generator to seed itself.
        byte[] someBytes = new byte[48];
        random.nextBytes(someBytes);
    }
}