Beispiel #1
0
 /** Generate a Diffie-Hellman keypair of the specified size. */
 DHCrypt(int keyLength, SecureRandom random) {
   try {
     KeyPairGenerator kpg = JsseJce.getKeyPairGenerator("DiffieHellman");
     kpg.initialize(keyLength, random);
     KeyPair kp = kpg.generateKeyPair();
     privateKey = kp.getPrivate();
     DHPublicKeySpec spec = getDHPublicKeySpec(kp.getPublic());
     publicValue = spec.getY();
     modulus = spec.getP();
     base = spec.getG();
   } catch (GeneralSecurityException e) {
     throw new RuntimeException("Could not generate DH keypair", e);
   }
 }