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);
}
}
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");
}
}
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()));
}
Aggregations