public override bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm) { var publicKey = new PublicKey(new Oid(KnownOids.X509Algorithms.RSA), new AsnEncodedData(_key), AsnNull); var rsa = publicKey.Key as RSACryptoServiceProvider; if (rsa == null) { return(false); } return(rsa.VerifyData(data, SctHashAlgorithmToOid(algorithm), signature)); }
private static string SctHashAlgorithmToOid(SctHashAlgorithm algorithm) { switch (algorithm) { case SctHashAlgorithm.HASH_ALGO_SHA1: return(KnownOids.HashAlgorithms.sha1); case SctHashAlgorithm.HASH_ALGO_SHA256: return(KnownOids.HashAlgorithms.sha256); case SctHashAlgorithm.HASH_ALGO_SHA384: return(KnownOids.HashAlgorithms.sha384); case SctHashAlgorithm.HASH_ALGO_SHA512: return(KnownOids.HashAlgorithms.sha512); default: return(null); } }
private static CngAlgorithm SctHashAlgorithmToCng(SctHashAlgorithm algorithm) { switch (algorithm) { case SctHashAlgorithm.HASH_ALGO_SHA1: return(CngAlgorithm.Sha1); case SctHashAlgorithm.HASH_ALGO_SHA256: return(CngAlgorithm.Sha256); case SctHashAlgorithm.HASH_ALGO_SHA384: return(CngAlgorithm.Sha384); case SctHashAlgorithm.HASH_ALGO_SHA512: return(CngAlgorithm.Sha512); default: return(null); } }
public override bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm) { byte[] blob; if (!EcdsaKeyFormatter.ToEcdsa256PublicKeyBlob(_key, out blob)) { return(false); } using (var key = CngKey.Import(blob, CngKeyBlobFormat.EccPublicBlob, CngProvider.MicrosoftSoftwareKeyStorageProvider)) { using (var ecdsa = new ECDsaCng(key)) { var hashAlgorithm = SctHashAlgorithmToCng(algorithm); if (hashAlgorithm == null) { return(false); } ecdsa.HashAlgorithm = hashAlgorithm; return(ecdsa.VerifyData(data, signature)); } } }
private static string SctHashAlgorithmToOid(SctHashAlgorithm algorithm) { switch (algorithm) { case SctHashAlgorithm.HASH_ALGO_SHA1: return KnownOids.HashAlgorithms.sha1; case SctHashAlgorithm.HASH_ALGO_SHA256: return KnownOids.HashAlgorithms.sha256; case SctHashAlgorithm.HASH_ALGO_SHA384: return KnownOids.HashAlgorithms.sha384; case SctHashAlgorithm.HASH_ALGO_SHA512: return KnownOids.HashAlgorithms.sha512; default: return null; } }
private static CngAlgorithm SctHashAlgorithmToCng(SctHashAlgorithm algorithm) { switch (algorithm) { case SctHashAlgorithm.HASH_ALGO_SHA1: return CngAlgorithm.Sha1; case SctHashAlgorithm.HASH_ALGO_SHA256: return CngAlgorithm.Sha256; case SctHashAlgorithm.HASH_ALGO_SHA384: return CngAlgorithm.Sha384; case SctHashAlgorithm.HASH_ALGO_SHA512: return CngAlgorithm.Sha512; default: return null; } }
public override bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm) { var publicKey = new PublicKey(new Oid(KnownOids.X509Algorithms.RSA), new AsnEncodedData(_key), AsnNull); var rsa = publicKey.Key as RSACryptoServiceProvider; if (rsa == null) { return false; } return rsa.VerifyData(data, SctHashAlgorithmToOid(algorithm), signature); }
public override bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm) { byte[] blob; if(!EcdsaKeyFormatter.ToEcdsa256PublicKeyBlob(_key, out blob)) { return false; } using (var key = CngKey.Import(blob, CngKeyBlobFormat.EccPublicBlob, CngProvider.MicrosoftSoftwareKeyStorageProvider)) { using (var ecdsa = new ECDsaCng(key)) { var hashAlgorithm = SctHashAlgorithmToCng(algorithm); if (hashAlgorithm == null) { return false; } ecdsa.HashAlgorithm = hashAlgorithm; return ecdsa.VerifyData(data, signature); } } }
public abstract bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm);