/** * Extracts a byte array representation of a private key given a keypair. * * @param privkey The keypair from which to get the private key. * * @return The underlying byte array of the private key or null upon failure. */ protected static byte[] encodeDHPrivateKey(DHPrivateKeyParameters privkey) { return privkey.getX().toByteArray(); }
public boolean equals( Object obj) { if (!(obj instanceof DHPrivateKeyParameters)) { return false; } DHPrivateKeyParameters other = (DHPrivateKeyParameters)obj; return other.getX().equals(this.x) && super.equals(obj); } }
public boolean equals( Object obj) { if (!(obj instanceof DHPrivateKeyParameters)) { return false; } DHPrivateKeyParameters other = (DHPrivateKeyParameters)obj; return other.getX().equals(this.x) && super.equals(obj); } }
BigInteger result = peerY.modPow(key.getX(), p); if (result.equals(ONE))
return message.modPow(key.getX(), p).multiply(result).mod(p);
/** * given a message from a given party and the corresponding public key, * calculate the next message in the agreement sequence. In this case * this will represent the shared secret. */ public BigInteger calculateAgreement( DHPublicKeyParameters pub, BigInteger message) { if (!pub.getParameters().equals(dhParams)) { throw new IllegalArgumentException("Diffie-Hellman public key has wrong parameters."); } BigInteger p = dhParams.getP(); return message.modPow(key.getX(), p).multiply(pub.getY().modPow(privateValue, p)).mod(p); } }
/** * given a short term public key from a given party calculate the next * message in the agreement sequence. */ public BigInteger calculateAgreement( CipherParameters pubKey) { DHPublicKeyParameters pub = (DHPublicKeyParameters)pubKey; if (!pub.getParameters().equals(dhParams)) { throw new IllegalArgumentException("Diffie-Hellman public key has wrong parameters."); } return pub.getY().modPow(key.getX(), dhParams.getP()); } }
/** * calculate our initial message. */ public BigInteger calculateMessage() { DHKeyPairGenerator dhGen = new DHKeyPairGenerator(); dhGen.init(new DHKeyGenerationParameters(random, dhParams)); AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair(); this.privateValue = ((DHPrivateKeyParameters)dhPair.getPrivate()).getX(); return ((DHPublicKeyParameters)dhPair.getPublic()).getY(); }
JCEDHPrivateKey( DHPrivateKeyParameters params) { this.x = params.getX(); this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL()); }
BCDHPrivateKey( DHPrivateKeyParameters params) { this.x = params.getX(); this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL()); }
BCDHPrivateKey( DHPrivateKeyParameters params) { this.x = params.getX(); this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL()); }
JCEDHPrivateKey( DHPrivateKeyParameters params) { this.x = params.getX(); this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL()); }
/** * calculate our initial message. */ public BigInteger calculateMessage() { DHKeyPairGenerator dhGen = new DHKeyPairGenerator(); dhGen.init(new DHKeyGenerationParameters(random, dhParams)); AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair(); this.privateValue = ((DHPrivateKeyParameters)dhPair.getPrivate()).getX(); return ((DHPublicKeyParameters)dhPair.getPublic()).getY(); }