private static bool VerifyStream(Stream dataStream, TagSignature signature, RSAParameters parameters) { try { if (signature.Required().Algorithm != Algorithm.RSA) { throw new InvalidDataException($"Signature uses different algorithm {signature.Algorithm} from this RSA key!"); } if (parameters.Exponent == null || parameters.Modulus == null) { throw new InvalidDataException($"This RSA key is not properly configured to be able to verify a signature!"); } using var RSAalg = OpenProvider(parameters); return(RSAalg.VerifyData(dataStream, signature.Data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1)); } catch (CryptographicException e) { throw new InterlockLedgerCryptographicException("Failed to verify data with current parameters and signature", e); } }
private static bool VerifyStream(Stream dataStream, TagSignature signature, ECParameters parameters) { try { if (signature.Required().Algorithm != Algorithm.EcDSA) { throw new InvalidDataException($"Signature uses different algorithm {signature.Algorithm} from this ECDsa key!"); } if (parameters.D == null) { throw new InvalidDataException($"This ECDsa key is not properly configured to be able to verify a signature!"); } using var algo = OpenWith(parameters); return(algo.VerifyData(dataStream, signature.Data, ECDsaParameters.ChooseHashAlgo(parameters.Curve).ToName())); } catch (CryptographicException e) { throw new InterlockLedgerCryptographicException("Failed to verify data with current parameters and signature", e); } }
public IdentifiedSignature(TagSignature signature, BaseKeyId id, TagPubKey publicKey) : this() { Signature = signature.Required(); SignerId = id.Required(); PublicKey = publicKey.Required(); }