FileDocCategorySizeDatePackage
DHAgreement.javaAPI DocExample5032Sat Jan 13 14:02:46 GMT 2001javasec.samples.ch10

DHAgreement

public class DHAgreement extends Object implements Runnable

Fields Summary
byte[]
bob
byte[]
alice
boolean
doneAlice
byte[]
ciphertext
BigInteger
aliceP
BigInteger
aliceG
int
aliceL
Constructors Summary
Methods Summary
public synchronized voiddoAlice()

        try {
            // Step 1:  Alice generates a key pair
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH");
            kpg.initialize(1024);
            KeyPair kp = kpg.generateKeyPair();
            
            // Step 2:  Alice sends the public key and the
            //         Diffie-Hellman key parameters to Bob
            Class dhClass = Class.forName(
                                "javax.crypto.spec.DHParameterSpec");
            DHParameterSpec dhSpec = (
                            (DHPublicKey) kp.getPublic()).getParams();
            aliceG = dhSpec.getG();
            aliceP = dhSpec.getP();
            aliceL = dhSpec.getL();
            alice = kp.getPublic().getEncoded();
            notify();

            // Step 4 part 1:  Alice performs the first phase of the
            //        protocol with her private key
            KeyAgreement ka = KeyAgreement.getInstance("DH");
            ka.init(kp.getPrivate());

            // Step 4 part 2:  Alice performs the second phase of the
            //        protocol with Bob