List of usage examples for org.bouncycastle.jce.spec ElGamalParameterSpec getG
public BigInteger getG()
g
. 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();//www .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 }
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 ww .j a v a 2 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); }