FileDocCategorySizeDatePackage
KeyAgreementThread.javaAPI DocAndroid 1.5 API3217Wed May 06 22:41:02 BST 2009org.apache.harmony.crypto.tests.javax.crypto.func

KeyAgreementThread

public class KeyAgreementThread extends TestThread

Fields Summary
Constructors Summary
public KeyAgreementThread(String[] names)

        super(names);
    
Methods Summary
public voidtest()

        AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DH");
        apg.init(1024, new SecureRandom());
        AlgorithmParameters ap = apg.generateParameters();
        DHParameterSpec ps = ap.getParameterSpec(DHParameterSpec.class);

        KeyAgreementGen kag1 = new KeyAgreementGen(ps);
        KeyAgreementGen kag2 = new KeyAgreementGen(ps);
        
        byte[] bArray1 = kag1.getPublicKeyBytes();
        byte[] bArray2 = kag2.getPublicKeyBytes();
        
        byte[] sk1 = kag1.getSecretKey(algName, bArray2);
        byte[] sk2 = kag2.getSecretKey(algName, bArray1);
        
        if (Arrays.areEqual(sk1, sk2) == false) {
            throw new Exception ("Generated keys are not the same");
        }