List of usage examples for org.bouncycastle.jce.spec ElGamalPublicKeySpec ElGamalPublicKeySpec
public ElGamalPublicKeySpec(BigInteger y, ElGamalParameterSpec spec)
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;// w w w. ja v a 2 s .com 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:SELSKeyGen.java
License:Open Source License
private static void CKeyGen(String userid, String randomStr, String LSPass, int expsec) throws Exception { KeyPairGenerator dsaKpg = KeyPairGenerator.getInstance("DSA", "BC"); KeyPair dsaKp;/*w w w . ja v a2 s. c o m*/ //KeyPairGenerator elgKpg; ElGamalParameterSpec elParams = new ElGamalParameterSpec(p, g); KeyPair elgKp; System.out.println(userid); System.out.println(randomStr); System.out.println(LSPass); // read a random BigInteger BigInteger r = new BigInteger(randomStr); // LS PGPPublicKey pgpPubKey = readPublicKey(new FileInputStream(SELS_LIST_PATH + "/LS_pub.asc")); PGPPrivateKey pgpSecKey = findSecretKey(new FileInputStream(SELS_LIST_PATH + "/LS_secret.asc"), pgpPubKey.getKeyID(), LSPass.toCharArray()); secKeyLS = (ElGamalPrivateKey) pgpSecKey.getKey(); BigInteger K_LS = secKeyLS.getX(); // User A's correspoding FileOutputStream out1 = new FileOutputStream(SELS_LIST_PATH + "/" + userid + "_secret.asc"); FileOutputStream out2 = new FileOutputStream(SELS_LIST_PATH + "/" + userid + "_pub.asc"); dsaKpg = KeyPairGenerator.getInstance("DSA", "BC"); dsaKpg.initialize(1024); dsaKp = dsaKpg.generateKeyPair(); BigInteger x; if (paramFlag == 1) x = K_LS.subtract(r).mod(p); else x = K_LS.subtract(r).mod(q); BigInteger y = g.modPow(x, p); ElGamalPrivateKeySpec privSpec = new ElGamalPrivateKeySpec(x, 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, LSPass.toCharArray(), true, expsec); }
From source file:SELSKeyGen.java
License:Open Source License
private static void userKeyGen(String subuserid, String servuserid, String subuserIdHash, String servuserIdHash, String LMPass, String userPass, int expsec) throws Exception { // this takes a while as the key generator has to generate // some DSA params // before it generates the key. KeyPairGenerator dsaKpg = KeyPairGenerator.getInstance("DSA", "BC"); KeyPair dsaKp;//w w w .java 2 s .c o m //KeyPairGenerator elgKpg; ElGamalParameterSpec elParams = new ElGamalParameterSpec(p, g); // this is quicker because we are using pregenerated parameters. KeyPair elgKp;// = elgKpg.generateKeyPair(); System.out.println(subuserid); System.out.println(servuserid); // generate a random BigInteger BigInteger r = genRandom(); // LM PGPPublicKey pgpPubKey = readPublicKey(new FileInputStream(SELS_LIST_PATH + "/LM_pub.asc")); PGPPrivateKey pgpSecKey = findSecretKey(new FileInputStream(SELS_LIST_PATH + "/LM_secret.asc"), pgpPubKey.getKeyID(), LMPass.toCharArray()); secKeyLM = (ElGamalPrivateKey) pgpSecKey.getKey(); BigInteger K_LM = secKeyLM.getX(); // User A's sub key FileOutputStream out1 = new FileOutputStream(SELS_LIST_PATH + "/" + subuserIdHash + "_subsecret.asc"); FileOutputStream out2 = new FileOutputStream(SELS_LIST_PATH + "/" + subuserIdHash + "_subpub.asc"); // User A's serv key FileOutputStream out3 = new FileOutputStream(SELS_LIST_PATH + "/" + servuserIdHash + "_servsecret.asc"); FileOutputStream out4 = new FileOutputStream(SELS_LIST_PATH + "/" + servuserIdHash + "_servpub.asc"); dsaKpg = KeyPairGenerator.getInstance("DSA", "BC"); dsaKpg.initialize(1024); dsaKp = dsaKpg.generateKeyPair(); BigInteger x; if (paramFlag == 1) x = K_LM.add(r).mod(p); else x = K_LM.add(r).mod(q); BigInteger y = g.modPow(x, p); ElGamalPrivateKeySpec privSpec = new ElGamalPrivateKeySpec(x, 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, subuserid, userPass.toCharArray(), true, expsec); exportKeyPair(out3, out4, dsaKp, elgKp, servuserid, userPass.toCharArray(), true, expsec); }