Example usage for org.bouncycastle.asn1.oiw ElGamalParameter ElGamalParameter

List of usage examples for org.bouncycastle.asn1.oiw ElGamalParameter ElGamalParameter

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.oiw ElGamalParameter ElGamalParameter.

Prototype

public ElGamalParameter(BigInteger p, BigInteger g) 

Source Link

Usage

From source file:ElGamalPrivatePGKey.java

License:Open Source License

/**
 * Return a PKCS8 representation of the key. The sequence returned
 * represents a full PrivateKeyInfo object.
 *
 * @return a PKCS8 representation of the key.
 *///from  w  w w. jav a2 s .  com
public byte[] getEncoded() {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    PrivateKeyInfo info = new PrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm,
            new ElGamalParameter(elSpec.getP(), elSpec.getG()).getDERObject()), new DERInteger(getX()));

    try {
        dOut.writeObject(info);
        dOut.close();
    } catch (IOException e) {
        throw new RuntimeException("Error encoding ElGamal private key");
    }

    return bOut.toByteArray();
}

From source file:ElGamalPublicPGKey.java

License:Open Source License

public byte[] getEncoded() {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
            new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm,
                    new ElGamalParameter(elSpec.getP(), elSpec.getG()).getDERObject()),
            new DERInteger(y));

    try {//from ww  w.ja  v  a  2  s  . c  om
        dOut.writeObject(info);
        dOut.close();
    } catch (IOException e) {
        throw new RuntimeException("Error encoding ElGamal public key");
    }

    return bOut.toByteArray();

}