Search in sources :

Example 16 with ECPrivateKey

use of java.security.interfaces.ECPrivateKey in project robovm by robovm.

the class ECDHKeyAgreementTest method testKnownAnswer.

/**
     * Performs a known-answer test of the shared secret for all permutations of {@code Providers}
     * of: first key pair, second key pair, and the {@code KeyAgreement}. This is to check that
     * the {@code KeyAgreement} instances work with keys of all registered providers.
     */
public void testKnownAnswer() throws Exception {
    for (Provider keyFactoryProvider1 : getKeyFactoryProviders()) {
        ECPrivateKey privateKey1 = getPrivateKey(KAT_PRIVATE_KEY1_PKCS8, keyFactoryProvider1);
        ECPublicKey publicKey1 = getPublicKey(KAT_PUBLIC_KEY1_X509, keyFactoryProvider1);
        for (Provider keyFactoryProvider2 : getKeyFactoryProviders()) {
            ECPrivateKey privateKey2 = getPrivateKey(KAT_PRIVATE_KEY2_PKCS8, keyFactoryProvider2);
            ECPublicKey publicKey2 = getPublicKey(KAT_PUBLIC_KEY2_X509, keyFactoryProvider2);
            for (Provider keyAgreementProvider : getKeyAgreementProviders()) {
                try {
                    testKnownAnswer(publicKey1, privateKey1, publicKey2, privateKey2, keyAgreementProvider);
                } catch (Throwable e) {
                    throw new RuntimeException(getClass().getSimpleName() + ".testKnownAnswer(" + keyFactoryProvider1.getName() + ", " + keyFactoryProvider2.getName() + ", " + keyAgreementProvider.getName() + ")", e);
                }
            }
        }
    }
}
Also used : ECPrivateKey(java.security.interfaces.ECPrivateKey) ECPublicKey(java.security.interfaces.ECPublicKey) Provider(java.security.Provider)

Aggregations

ECPrivateKey (java.security.interfaces.ECPrivateKey)16 KeyPairGenerator (java.security.KeyPairGenerator)9 ECPublicKey (java.security.interfaces.ECPublicKey)8 KeyFactory (java.security.KeyFactory)6 KeyPair (java.security.KeyPair)6 BigInteger (java.math.BigInteger)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Signature (java.security.Signature)4 ECParameterSpec (java.security.spec.ECParameterSpec)4 ECPoint (java.security.spec.ECPoint)4 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)4 GeneralSecurityException (java.security.GeneralSecurityException)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)3 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)3 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)3 KeyAgreement (javax.crypto.KeyAgreement)3 InvalidKeyException (java.security.InvalidKeyException)2 PrivateKey (java.security.PrivateKey)2 Provider (java.security.Provider)2