Search in sources :

Example 1 with EcdsaVerifyJce

use of com.google.crypto.tink.subtle.EcdsaVerifyJce in project tink by google.

the class RewardedAdsVerifier method verify.

private void verify(final byte[] tbs, long keyId, final byte[] signature) throws GeneralSecurityException {
    boolean foundKeyId = false;
    for (VerifyingPublicKeysProvider provider : verifyingPublicKeysProviders) {
        Map<Long, ECPublicKey> publicKeys = provider.get();
        if (publicKeys.containsKey(keyId)) {
            foundKeyId = true;
            ECPublicKey publicKey = publicKeys.get(keyId);
            EcdsaVerifyJce verifier = new EcdsaVerifyJce(publicKey, "SHA256WithECDSA");
            verifier.verify(signature, tbs);
        }
    }
    if (!foundKeyId) {
        throw new GeneralSecurityException("cannot find verifying key with key id: " + keyId);
    }
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) GeneralSecurityException(java.security.GeneralSecurityException) EcdsaVerifyJce(com.google.crypto.tink.subtle.EcdsaVerifyJce)

Example 2 with EcdsaVerifyJce

use of com.google.crypto.tink.subtle.EcdsaVerifyJce in project tink by google.

the class PaymentMethodTokenRecipient method verify.

private static void verify(final String protocolVersion, final List<SenderVerifyingKeysProvider> senderVerifyingKeysProviders, final List<byte[]> signatures, final byte[] signedBytes) throws GeneralSecurityException {
    boolean verified = false;
    for (SenderVerifyingKeysProvider verifyingKeysProvider : senderVerifyingKeysProviders) {
        for (ECPublicKey publicKey : verifyingKeysProvider.get(protocolVersion)) {
            EcdsaVerifyJce verifier = new EcdsaVerifyJce(publicKey, PaymentMethodTokenConstants.ECDSA_SHA256_SIGNING_ALGO);
            for (byte[] signature : signatures) {
                try {
                    verifier.verify(signature, signedBytes);
                    // No exception means the signature is valid.
                    verified = true;
                } catch (GeneralSecurityException e) {
                // ignored, try again
                }
            }
        }
    }
    if (!verified) {
        throw new GeneralSecurityException("cannot verify signature");
    }
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) GeneralSecurityException(java.security.GeneralSecurityException) EcdsaVerifyJce(com.google.crypto.tink.subtle.EcdsaVerifyJce)

Example 3 with EcdsaVerifyJce

use of com.google.crypto.tink.subtle.EcdsaVerifyJce in project tink by google.

the class EcdsaVerifyKeyManager method getPrimitive.

/**
 * @param key {@code EcdsaPublicKey} proto
 */
@Override
public PublicKeyVerify getPrimitive(MessageLite key) throws GeneralSecurityException {
    if (!(key instanceof EcdsaPublicKey)) {
        throw new GeneralSecurityException("expected EcdsaPublicKey proto");
    }
    EcdsaPublicKey keyProto = (EcdsaPublicKey) key;
    validate(keyProto);
    ECPublicKey publicKey = EllipticCurves.getEcPublicKey(SigUtil.toCurveType(keyProto.getParams().getCurve()), keyProto.getX().toByteArray(), keyProto.getY().toByteArray());
    return new EcdsaVerifyJce(publicKey, SigUtil.toEcdsaAlgo(keyProto.getParams().getHashType()));
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) EcdsaPublicKey(com.google.crypto.tink.proto.EcdsaPublicKey) GeneralSecurityException(java.security.GeneralSecurityException) EcdsaVerifyJce(com.google.crypto.tink.subtle.EcdsaVerifyJce)

Aggregations

EcdsaVerifyJce (com.google.crypto.tink.subtle.EcdsaVerifyJce)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ECPublicKey (java.security.interfaces.ECPublicKey)3 EcdsaPublicKey (com.google.crypto.tink.proto.EcdsaPublicKey)1