Java 类org.bouncycastle.crypto.agreement.DHAgreement 实例源码

项目:gwt-crypto    文件:DHTest.java   
private void testGPWithRandom(
    DHKeyPairGenerator kpGen)
{
    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
    e2.init(new ParametersWithRandom(pv2, new SecureRandom()));

    BigInteger   m1 = e1.calculateMessage();
    BigInteger   m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail("basic with random 2-way test failed");
    }
}
项目:irma_future_id    文件:DHTest.java   
private void testGPWithRandom(
    DHKeyPairGenerator kpGen)
{
    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
    e2.init(new ParametersWithRandom(pv2, new SecureRandom()));

    BigInteger   m1 = e1.calculateMessage();
    BigInteger   m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail("basic with random 2-way test failed");
    }
}
项目:bc-java    文件:DHTest.java   
private void testGPWithRandom(
    DHKeyPairGenerator kpGen)
{
    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
    e2.init(new ParametersWithRandom(pv2, new SecureRandom()));

    BigInteger   m1 = e1.calculateMessage();
    BigInteger   m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail("basic with random 2-way test failed");
    }
}
项目:gwt-crypto    文件:DHTest.java   
private void testDH(
    int         size,
    BigInteger  g,
    BigInteger  p)
{
    DHKeyPairGenerator kpGen = getDHKeyPairGenerator(g, p);

    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(pv1);
    e2.init(pv2);

    BigInteger  m1 = e1.calculateMessage();
    BigInteger  m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail(size + " bit 2-way test failed");
    }
}
项目:irma_future_id    文件:DHTest.java   
private void testDH(
    int         size,
    BigInteger  g,
    BigInteger  p)
{
    DHKeyPairGenerator kpGen = getDHKeyPairGenerator(g, p);

    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(pv1);
    e2.init(pv2);

    BigInteger  m1 = e1.calculateMessage();
    BigInteger  m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail(size + " bit 2-way test failed");
    }
}
项目:bc-java    文件:DHTest.java   
private void testDH(
    int         size,
    BigInteger  g,
    BigInteger  p)
{
    DHKeyPairGenerator kpGen = getDHKeyPairGenerator(g, p);

    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(pv1);
    e2.init(pv2);

    BigInteger  m1 = e1.calculateMessage();
    BigInteger  m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);

    if (!k1.equals(k2))
    {
        fail(size + " bit 2-way test failed");
    }
}