Exemple #1
0
            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));
            }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
 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));
         }
     }
 }
Exemple #5
0
 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;
     }
 }
Exemple #6
0
 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;
     }
 }
Exemple #7
0
 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);
 }
Exemple #8
0
 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);
         }
     }
 }
Exemple #9
0
 public abstract bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm);
Exemple #10
0
 public abstract bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm);