Fix for GH-18

Need to explicitly tell the BigInteger constructor that K (generated secret) is a positive number.
This commit is contained in:
Shikhar Bhushan
2011-06-19 17:53:56 +01:00
parent 8b61d96808
commit eaee42b017

View File

@@ -75,7 +75,6 @@ public class DH {
final KeyPair kp = generator.generateKeyPair(); final KeyPair kp = generator.generateKeyPair();
agreement.init(kp.getPrivate()); agreement.init(kp.getPrivate());
e = ((javax.crypto.interfaces.DHPublicKey) kp.getPublic()).getY(); e = ((javax.crypto.interfaces.DHPublicKey) kp.getPublic()).getY();
} }
public void computeK(BigInteger f) public void computeK(BigInteger f)
@@ -83,8 +82,7 @@ public class DH {
final KeyFactory keyFactory = SecurityUtils.getKeyFactory("DH"); final KeyFactory keyFactory = SecurityUtils.getKeyFactory("DH");
final PublicKey yourPubKey = keyFactory.generatePublic(new DHPublicKeySpec(f, p, g)); final PublicKey yourPubKey = keyFactory.generatePublic(new DHPublicKeySpec(f, p, g));
agreement.doPhase(yourPubKey, true); agreement.doPhase(yourPubKey, true);
K = new BigInteger(agreement.generateSecret()); K = new BigInteger(1, agreement.generateSecret());
} }
public BigInteger getE() { public BigInteger getE() {