private bool CheckSignedInfo(AsymmetricAlgorithm key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     SignedXmlDebugLog.LogBeginCheckSignedInfo(this, this.m_signature.SignedInfo);
     SignatureDescription signatureDescription = CryptoConfig.CreateFromName(this.SignatureMethod) as SignatureDescription;
     if (signatureDescription == null)
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignatureDescriptionNotCreated"));
     }
     Type c = Type.GetType(signatureDescription.KeyAlgorithm);
     Type type = key.GetType();
     if (((c != type) && !c.IsSubclassOf(type)) && !type.IsSubclassOf(c))
     {
         return false;
     }
     HashAlgorithm hash = signatureDescription.CreateDigest();
     if (hash == null)
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CreateHashAlgorithmFailed"));
     }
     byte[] actualHashValue = this.GetC14NDigest(hash);
     AsymmetricSignatureDeformatter asymmetricSignatureDeformatter = signatureDescription.CreateDeformatter(key);
     SignedXmlDebugLog.LogVerifySignedInfo(this, key, signatureDescription, hash, asymmetricSignatureDeformatter, actualHashValue, this.m_signature.SignatureValue);
     return asymmetricSignatureDeformatter.VerifySignature(actualHashValue, this.m_signature.SignatureValue);
 }
Пример #2
0
        private bool CheckSignedInfo (AsymmetricAlgorithm key) {
            if (key == null)
                throw new ArgumentNullException("key");

            SignedXmlDebugLog.LogBeginCheckSignedInfo(this, m_signature.SignedInfo);

            SignatureDescription signatureDescription = CryptoConfig.CreateFromName(SignatureMethod) as SignatureDescription;
            if (signatureDescription == null)
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_SignatureDescriptionNotCreated"));

            // Let's see if the key corresponds with the SignatureMethod 
            Type ta = Type.GetType(signatureDescription.KeyAlgorithm);
            Type tb = key.GetType();
            if ((ta != tb) && !ta.IsSubclassOf(tb) && !tb.IsSubclassOf(ta)) 
                // Signature method key mismatch
                return false;

            HashAlgorithm hashAlgorithm = signatureDescription.CreateDigest();
            if (hashAlgorithm == null)
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CreateHashAlgorithmFailed"));
            byte[] hashval = GetC14NDigest(hashAlgorithm);

            AsymmetricSignatureDeformatter asymmetricSignatureDeformatter = signatureDescription.CreateDeformatter(key);
            SignedXmlDebugLog.LogVerifySignedInfo(this,
                                                  key,
                                                  signatureDescription,
                                                  hashAlgorithm,
                                                  asymmetricSignatureDeformatter,
                                                  hashval,
                                                  m_signature.SignatureValue);
            return asymmetricSignatureDeformatter.VerifySignature(hashval, m_signature.SignatureValue);
        }