Example usage for org.bouncycastle.jce.provider JCEElGamalPublicKey getParameters

List of usage examples for org.bouncycastle.jce.provider JCEElGamalPublicKey getParameters

Introduction

In this page you can find the example usage for org.bouncycastle.jce.provider JCEElGamalPublicKey getParameters.

Prototype

public ElGamalParameterSpec getParameters() 

Source Link

Usage

From source file:SELSKeyGen.java

License:Open Source License

public static void initPGQ() throws Exception {
    String paramFile = SELS_LIST_PATH + "/params.gpg";
    File file = new File(paramFile);
    if (file.exists()) {
        PGPPublicKey pgpPubKey = readPublicKey(new FileInputStream(paramFile));
        JCEElGamalPublicKey pubKey = (JCEElGamalPublicKey) pgpPubKey.getKey("BC");
        ElGamalParameterSpec spec = pubKey.getParameters();
        p = spec.getP();//w  w w  .j  a v a  2 s  .  c o m
        g = spec.getG();
        orderQ = p.bitLength() / 8;
        paramFlag = 1;

        System.out.println("P: = " + p.toString());
        System.out.println("G: = " + g.toString());

    } // end if
    else {
        paramFile = SELS_LIST_PATH + "/params";
        BufferedReader in = new BufferedReader(new FileReader(paramFile));

        while (true) {
            String line = in.readLine();
            if (line == null)
                break;
            String wlist[] = line.split("\\s");

            if (wlist[0].equals("g:"))
                g = new BigInteger(wlist[1]);
            else if (wlist[0].equals("p:"))
                p = new BigInteger(wlist[1]);
            else if (wlist[0].equals("q:"))
                q = new BigInteger(wlist[1]);
        } // end while
        orderQ = q.bitLength() / 8;
        paramFlag = 0;

    } // end else

}