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

org.spongycastle.crypto.generators.ElGamalParametersGenerator Maven / Gradle / Ivy

Go to download

Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android. Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add an alternative (updated/complete) Bouncy Castle jar. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.

There is a newer version: 1.46.99.3-UNOFFICIAL-ROBERTO-RELEASE
Show newest version
package org.spongycastle.crypto.generators;

import org.spongycastle.crypto.params.ElGamalParameters;

import java.math.BigInteger;
import java.security.SecureRandom;

public class ElGamalParametersGenerator
{
    private int             size;
    private int             certainty;
    private SecureRandom    random;

    public void init(
        int             size,
        int             certainty,
        SecureRandom    random)
    {
        this.size = size;
        this.certainty = certainty;
        this.random = random;
    }

    /**
     * which generates the p and g values from the given parameters,
     * returning the ElGamalParameters object.
     * 

* Note: can take a while... */ public ElGamalParameters generateParameters() { // // find a safe prime p where p = 2*q + 1, where p and q are prime. // BigInteger[] safePrimes = DHParametersHelper.generateSafePrimes(size, certainty, random); BigInteger p = safePrimes[0]; BigInteger q = safePrimes[1]; BigInteger g = DHParametersHelper.selectGenerator(p, q, random); return new ElGamalParameters(p, g); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy