Search in sources :

Example 6 with DHPrivateKeySpec

use of javax.crypto.spec.DHPrivateKeySpec in project j2objc by google.

the class DHPrivateKeySpecTest method testDHPrivateKeySpec.

/**
 * DHPrivateKeySpec class testing. Tests the equivalence of parameters
 * specified in the constructor with the values returned by getters.
 */
public void testDHPrivateKeySpec() {
    BigInteger[] xs = { new BigInteger("-1000000000000"), BigInteger.ZERO, BigInteger.ONE, new BigInteger("1000000000000") };
    BigInteger[] ps = { new BigInteger("-1000000000000"), BigInteger.ZERO, BigInteger.ONE, new BigInteger("1000000000000") };
    BigInteger[] gs = { new BigInteger("-1000000000000"), BigInteger.ZERO, BigInteger.ONE, new BigInteger("1000000000000") };
    for (int i = 0; i < ps.length; i++) {
        DHPrivateKeySpec dhpks = new DHPrivateKeySpec(xs[i], ps[i], gs[i]);
        assertEquals("The value returned by getX() must be " + "equal to the value specified in the constructor", dhpks.getX(), xs[i]);
        assertEquals("The value returned by getP() must be " + "equal to the value specified in the constructor", dhpks.getP(), ps[i]);
        assertEquals("The value returned by getG() must be " + "equal to the value specified in the constructor", dhpks.getG(), gs[i]);
    }
}
Also used : DHPrivateKeySpec(javax.crypto.spec.DHPrivateKeySpec) BigInteger(java.math.BigInteger)

Aggregations

DHPrivateKeySpec (javax.crypto.spec.DHPrivateKeySpec)6 BigInteger (java.math.BigInteger)3 DHParameterSpec (javax.crypto.spec.DHParameterSpec)3 DHPublicKeySpec (javax.crypto.spec.DHPublicKeySpec)3 KeyFactory (java.security.KeyFactory)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)2 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)2 DHPrivateKey (javax.crypto.interfaces.DHPrivateKey)2 IOException (java.io.IOException)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyPair (java.security.KeyPair)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PrivateKey (java.security.PrivateKey)1 SecureRandom (java.security.SecureRandom)1 SecretKeyFactory (javax.crypto.SecretKeyFactory)1 DHPublicKey (javax.crypto.interfaces.DHPublicKey)1 AsymmetricCipherKeyPair (org.spongycastle.crypto.AsymmetricCipherKeyPair)1 DHKeyPairGenerator (org.spongycastle.crypto.generators.DHKeyPairGenerator)1 DHKeyGenerationParameters (org.spongycastle.crypto.params.DHKeyGenerationParameters)1