Ejemplo n.º 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));
            }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
         }
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 9
0
 public abstract bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm);
Ejemplo n.º 10
0
 public abstract bool Verify(byte[] data, byte[] signature, SctHashAlgorithm algorithm);