我对XMLDSig的这一点很感兴趣。我的XML需要签名。在我参与的项目中,我需要在符号之前和符号之后对XSD验证XML。使用XSD验证签名的XML - xmldsig
我不太了解XSD,但我认为在这里有一个导入到另一个XSD。这就是我的烦恼开始的地方。我的XSD文件是masive.xsd这就是它在开始时的样子。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="xmldsig-core-schema.xsd"/>
在我的代码C#我使用一些代码,我在网上发现,可行的,因为当我试图验证对XSD的XML它显示了发现的错误。但是,当我尝试验证已签名的XML是我的麻烦开始的地方。
如果我按照原样使用该类,则不作任何更改。当我与功能pathSchema添加架构:
SchemaSet.Add(null, pathSchema); //pathSchema is the path where my xsd file is.
我得到这个错误:
The 'http://www.w3.org/2000/09/xmldsig#:Signature' element is not declared.
如果我是正确的,这是因为签署了XML有一些标签这样的:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig-aae8151c-b8db-4525-bfb1-0b3cebdd1dbf">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<ds:Reference URI="#xmldsig-aae8151c-b8db-4525-bfb1-0b3cebdd1dbf-keyinfo">
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>p4U9Np1nKtjWPPwp2mOcIimRjUy+RuQIPr2hVdY5R2E=</ds:DigestValue>
</ds:Reference>
我读过一些帖子之前,在其中一个我读过的人添加了手动XSD我想。于是我下载了XSD并投入本地路径,然后我加入到我的代码:
XElement xsdMarkup2 = XElement.Load(@"C:\XMLXSD\xmldsig-core-schema.xsd");
settings.Schemas.Add(null, xsdMarkup2.CreateReader());
和错误“签名元素没有被宣布为”不显示。但是,验证程序不再验证已签名的XML。因为我删除了一些标签,并且班级说:没有错误。但有。