Example usage for org.bouncycastle.bcpg DSAPublicBCPGKey DSAPublicBCPGKey

List of usage examples for org.bouncycastle.bcpg DSAPublicBCPGKey DSAPublicBCPGKey

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg DSAPublicBCPGKey DSAPublicBCPGKey.

Prototype

public DSAPublicBCPGKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y) 

Source Link

Usage

From source file:genkeys.java

License:Open Source License

private static PublicKeyPacket publicKeyPacket(PublicKey key, int algorithm, Date time) throws PGPException {
    BCPGKey bcpgKey;//  w  w w.  j  a va2 s .c om
    if (key instanceof RSAPublicKey) {
        RSAPublicKey rK = (RSAPublicKey) key;
        bcpgKey = new RSAPublicBCPGKey(rK.getModulus(), rK.getPublicExponent());
    } else if (key instanceof DSAPublicKey) {
        DSAPublicKey dK = (DSAPublicKey) key;
        DSAParams dP = dK.getParams();
        bcpgKey = new DSAPublicBCPGKey(dP.getP(), dP.getQ(), dP.getG(), dK.getY());
    } else if (key instanceof ElGamalPublicKey) {
        ElGamalPublicKey eK = (ElGamalPublicKey) key;
        ElGamalParameterSpec eS = eK.getParameters();
        bcpgKey = new ElGamalPublicBCPGKey(eS.getP(), eS.getG(), eK.getY());
    } else {
        throw new PGPException("unknown key class");
    }

    return new PublicKeyPacket(algorithm, time, bcpgKey);
}