Example usage for org.bouncycastle.jce.interfaces ElGamalPublicKey getY

List of usage examples for org.bouncycastle.jce.interfaces ElGamalPublicKey getY

Introduction

In this page you can find the example usage for org.bouncycastle.jce.interfaces ElGamalPublicKey getY.

Prototype

public BigInteger getY();

Source Link

Usage

From source file:ElGamalPublicPGKey.java

License:Open Source License

public ElGamalPublicPGKey(ElGamalPublicKey key) {
    this.y = key.getY();
    this.elSpec = key.getParameters();
}

From source file:SELSKeyGen.java

License:Open Source License

private static void LKKeyGen(String userId, String LKPass, int expsec) throws Exception {
    KeyPairGenerator dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");
    KeyPair dsaKp;//from ww  w .j  a va 2 s  .  c o  m
    KeyPairGenerator elgKpg;
    ElGamalParameterSpec elParams = new ElGamalParameterSpec(p, g);
    KeyPair elgKp;

    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");
    dsaKpg.initialize(1024);
    dsaKp = dsaKpg.generateKeyPair();

    elgKpg = KeyPairGenerator.getInstance("ELGAMAL", "BC");
    elgKpg.initialize(elParams);

    // generate a random BigInteger
    // BigInteger r = genRandom();

    ElGamalPublicKey pubKeyLM;
    ElGamalPublicKey pubKeyLS;
    //   LM
    PGPPublicKey pgpPubKey = readPublicKey(new FileInputStream(SELS_LIST_PATH + "/LM_pub.asc"));

    pubKeyLM = (ElGamalPublicKey) pgpPubKey.getKey("BC");
    BigInteger PK_LM = pubKeyLM.getY();

    //   LS
    pgpPubKey = readPublicKey(new FileInputStream(SELS_LIST_PATH + "/LS_pub.asc"));

    pubKeyLS = (ElGamalPublicKey) pgpPubKey.getKey("BC");
    BigInteger PK_LS = pubKeyLS.getY();

    // List Key
    FileOutputStream out1 = new FileOutputStream(SELS_LIST_PATH + "/rev_secret.asc");
    FileOutputStream out2 = new FileOutputStream(SELS_LIST_PATH + "/LK_pub.asc");

    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");
    dsaKpg.initialize(1024);
    dsaKp = dsaKpg.generateKeyPair();

    BigInteger y = PK_LS.multiply(PK_LM).mod(p);

    System.out.println(y);

    ElGamalPrivateKeySpec privSpec = new ElGamalPrivateKeySpec(new BigInteger("0"), elParams);
    ElGamalPublicKeySpec pubSpec = new ElGamalPublicKeySpec(y, elParams);
    ElGamalPublicPGKey pubKey = new ElGamalPublicPGKey(pubSpec);
    ElGamalPrivatePGKey secKey = new ElGamalPrivatePGKey(privSpec);

    elgKp = new KeyPair(pubKey, secKey);
    exportKeyPair(out1, out2, dsaKp, elgKp, userId, LKPass.toCharArray(), true, expsec);

}

From source file:genkeys.java

License:Open Source License

private static PublicKeyPacket publicKeyPacket(PublicKey key, int algorithm, Date time) throws PGPException {
    BCPGKey bcpgKey;//from   w w  w.j ava 2 s . c o  m
    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);
}