org.bouncycastle.crypto.test.X448Test Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk14 Show documentation
Show all versions of bcprov-jdk14 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.
package org.bouncycastle.crypto.test;
import java.security.SecureRandom;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
import org.bouncycastle.crypto.agreement.X448Agreement;
import org.bouncycastle.crypto.generators.X448KeyPairGenerator;
import org.bouncycastle.crypto.params.X448KeyGenerationParameters;
import org.bouncycastle.util.test.SimpleTest;
public class X448Test
extends SimpleTest
{
private static final SecureRandom RANDOM = new SecureRandom();
public String getName()
{
return "X448";
}
public static void main(String[] args)
{
runTest(new X448Test());
}
public void performTest()
{
for (int i = 0; i < 10; ++i)
{
testAgreement();
}
}
private void testAgreement()
{
AsymmetricCipherKeyPairGenerator kpGen = new X448KeyPairGenerator();
kpGen.init(new X448KeyGenerationParameters(RANDOM));
AsymmetricCipherKeyPair kpA = kpGen.generateKeyPair();
AsymmetricCipherKeyPair kpB = kpGen.generateKeyPair();
X448Agreement agreeA = new X448Agreement();
agreeA.init(kpA.getPrivate());
byte[] secretA = new byte[agreeA.getAgreementSize()];
agreeA.calculateAgreement(kpB.getPublic(), secretA, 0);
X448Agreement agreeB = new X448Agreement();
agreeB.init(kpB.getPrivate());
byte[] secretB = new byte[agreeB.getAgreementSize()];
agreeB.calculateAgreement(kpA.getPublic(), secretB, 0);
if (!areEqual(secretA, secretB))
{
fail("X448 agreement failed");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy