All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.generators.ElGamalKeyPairGenerator Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.5 and up. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.

There is a newer version: 1.2.2.1-jre17
Show newest version
package org.bouncycastle.crypto.generators;

import java.math.BigInteger;

import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.crypto.params.DHParameters;
import org.bouncycastle.crypto.params.ElGamalKeyGenerationParameters;
import org.bouncycastle.crypto.params.ElGamalParameters;
import org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters;
import org.bouncycastle.crypto.params.ElGamalPublicKeyParameters;

/**
 * a ElGamal key pair generator.
 * 

* This generates keys consistent for use with ElGamal as described in * page 164 of "Handbook of Applied Cryptography". */ public class ElGamalKeyPairGenerator implements AsymmetricCipherKeyPairGenerator { private ElGamalKeyGenerationParameters param; public void init( KeyGenerationParameters param) { this.param = (ElGamalKeyGenerationParameters)param; } public AsymmetricCipherKeyPair generateKeyPair() { DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE; ElGamalParameters egp = param.getParameters(); DHParameters dhp = new DHParameters(egp.getP(), egp.getG(), null, egp.getL()); BigInteger x = helper.calculatePrivate(dhp, param.getRandom()); BigInteger y = helper.calculatePublic(dhp, x); return new AsymmetricCipherKeyPair( new ElGamalPublicKeyParameters(y, egp), new ElGamalPrivateKeyParameters(x, egp)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy