标签: xml-signature

用于 XML 数字签名的命令行工具

是否有用于 XML 数字签名的命令行工具?

我在这里找到了一个: http: //www.codeproject.com/KB/security/xmldsiglic.aspx ,但它需要 .NET Framework,我更喜欢它在没有 .NET 的情况下工作

xml command-line digital-signature xml-signature

5
推荐指数
1
解决办法
1万
查看次数

有 xmlseclibs 的任何文档吗?

我已经签署了 XML,但我不知道如何在签名中包含 KeyValue 元素。拥有一些文档会节省很多时间。

下面的代码(如果您感兴趣的话)是我迄今为止使用 xmlseclibs 所做的事情:

<?php
require('xmlseclibs.php'); 
Run Code Online (Sandbox Code Playgroud)

XML字符串

$getToken = '<getToken>
<item>
<Semilla>Random string</Semilla>
</item>
</getToken>';
Run Code Online (Sandbox Code Playgroud)

创建 XML 对象(用于签名)

$getToken_DOMDocument = new DOMDocument(); 
$getToken_DOMDocument -> loadXml($getToken); 
Run Code Online (Sandbox Code Playgroud)

使用 xmlseclibs 创建签名对象

$getToken_XMLSecurityDSig = new XMLSecurityDSig(); 
$getToken_XMLSecurityDSig -> setCanonicalMethod(XMLSecurityDSig::C14N); 
Run Code Online (Sandbox Code Playgroud)

尝试关闭 ds: 前缀,但不起作用

$options['prefix'] = '';
$options['prefix_ns'] = '';
$options['force_uri'] = TRUE;
$options['id_name'] = 'ID';

$getToken_XMLSecurityDSig -> addReference($getToken_DOMDocument, XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'), $options); 
Run Code Online (Sandbox Code Playgroud)

访问必要的关键数据

$XMLSecurityKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private')); 
$XMLSecurityKey -> loadKey('../../DTE/certificado/firma/certificado.pem', TRUE); 
/* if key has Passphrase, set it using $objKey -> …
Run Code Online (Sandbox Code Playgroud)

php xml-signature xmlseclibs

5
推荐指数
1
解决办法
4407
查看次数

使用SignedXml.ComputeSignature将签名添加到配置文件后,"无法识别的配置部分"

我有一个使用.NET 3.5 Framework构建的Windows窗体应用程序,它自带一个WCF服务.服务和应用程序可以自行正常运行.

关于在app.config文件中可以访问地址和绑定信息,我决定使用System.Security.Cryptography.Xml.SignedXml.ComputeSignature添加数字签名.然后我将签名添加到app.config并保存.这会在app.config中创建一个Signature元素,作为app.config文件的配置节点的最后一个子元素.

我在启动服务之前添加了一个检查签名的函数.该应用程序正确验证签名,但在尝试启动该服务时,它会抛出以下嵌套错误:

  1. 'System.ServiceModel.DiagnosticUtility'的类型初始值设定项引发了异常.

2.配置系统无法初始化

3.无法识别的配置部分签名.

在app.config中放置Signature元素的位置似乎并不重要.签名始终可以正确验证,并且服务始终会对未识别的配置部分进行控制.注释掉app.config中的Signature元素和代码中的签名检查,服务将重新开始,没有任何问题.

为什么服务会抛出这些错误,我该怎么做才能解决它们?

这是带有编辑的应用程序名称和URL的app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyApp.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>     
        <binding name="MyAppServicePortBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://myappurl/MyService" binding="basicHttpBinding" bindingConfiguration="MyAppServicePortBinding" …
Run Code Online (Sandbox Code Playgroud)

.net configuration app-config xml-signature

4
推荐指数
1
解决办法
5028
查看次数

XML签名验证在java中失败

我有一个数字签名的 XML 文件和签名者的公共证书,我想验证签名。响应 xml 的原始内容返回 false,但是当我修改 xml 时它返回 true。我的java代码如下:-

import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
public class SignatureVerifierOneFile {
  public static void main(String[] args){       
        Security.addProvider(new BouncyCastleProvider());       
        //Signed xml path
        String signedXmlPath = "C:/signedXML.xml";      
        SignatureVerifierOneFile signatureVerifier = new SignatureVerifierOneFile();
        boolean signatureStatus = 
signatureVerifier.verify(signedXmlPath,"C:/Cert.cer");
        System.out.println("xml signature validateionis " + signatureStatus);

    }
    public boolean verify(String signedXml,String publicKeyFile) {

        boolean verificationResult = …
Run Code Online (Sandbox Code Playgroud)

java xml digital-signature xml-signature

4
推荐指数
1
解决办法
5865
查看次数

XSD签名问题

我无法解决这个错误<xs:element ref="ds:Signature"/>.我需要一些帮助.

版权所有(C)Microsoft Corporation.版权所有.架构验证警告:未声明' http://www.w3.org/2000/09/xmldsig#:Signature '元素.第162行,第8位.

警告:无法验证架构.类生成可能会失败或可能产生不正确的结果.

警告:无法生成类,因为找不到具有复杂类型的顶级元素.

XSD

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
            xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  attributeFormDefault="unqualified" elementFormDefault="qualified">

  <xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
             schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>

             <xs:complexType name="SobreCheques">
        <xs:annotation>
            <xs:documentation>Definition of the ...</xs:documentation>
        </xs:annotation>
        <xs:sequence>
             ...
      <xs:element ref="ds:Signature"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

xml xsd digital-signature visual-studio xml-signature

4
推荐指数
1
解决办法
4470
查看次数

如何使用 Spring Security SAML 扩展对 SAML 请求/响应进行签名

我能够使用 Spring Security SAML 扩展让我的应用程序充当具有IDP SSOCIRCLE的 SP。我的客户有以下要求:

1. 对断言进行签名:从 IDP 发送的断言已签名并且工作正常。

2. 对请求/响应进行签名:使用 SSO Circle 生成元数据文件时。我选择将AuthnRequestsSigned选项设置为true。我将 SP 元数据上传到 SSO Circle IDP。SP 元数据具有以下true值:AuthnRequestsSignedWantAssertionsSigned。运行应用程序时,我的请求和收到的响应都没有签名。

我在完成第二个要求时遇到问题。我对 SAML 和一般安全性还不熟悉。我在这里缺少什么?

更新

在考虑了弗拉基米尔的意见后。我将绑定更改为 HTTP-Post,因此现在我正在发送带有所示签名的 SAML 请求。我能够通过执行以下操作来发送使用我的私钥(不是示例项目提供的私钥)签名的请求:

  1. 使用 keygen 工具创建密钥库、CSR 和公钥证书。
  2. 更新我的 SP 元数据文件中的数字签名部分以获取新证书
  3. 从 IDP SSOCIRCLE 中删除旧的 SP 元数据文件并添加新的 SP 元数据文件
  4. 更改 spring 配置以使 JKSKeyManager 使用我使用新别名和密码创建的新密钥库。

我现在需要做的是让 IDP(SSOCIRCLE) 将响应发送到 a. 响应已签名 B. 断言已签署

如何才能做到这一点?鉴于响应的签名应该与断言的签名不同,我需要做哪些更改来处理这个问题。谢谢。

spring-security x509certificate saml-2.0 xml-signature spring-saml

3
推荐指数
1
解决办法
5050
查看次数

如何使用<x509certificate>(不是证书文件)验证C#中XML文件的签名?

我正在为政府计费系统制定一些代码,经过几周的阅读后,我达到了死胡同.

我需要验证从服务器收到的xml文件中的至少两个签名,我已经根据公共MSDN制作了一些代码,以便在我使用证书文件或x509store签名时验证签名,并且工作正常,我可以毫无困难地根据他们的参考签署和验证每个签名.

但是,当我收到文件时我不知道如何验证它,因为我没有证书文件,我当然知道里面有标签,如果我得到该值并将其放在openssl.exe上,我可以验证签名者的身份,但idk如何检查签名是否正确

http://puu.sh/dypRH/c45e200202.png

在过去我用过

if (signedXml.CheckSignature(cert, true))
Run Code Online (Sandbox Code Playgroud)

现在我尝试使用signedXml.CheckSignature())

每次都失败,我无法参考选择哪个签名,所以我做了一个

                foreach (XmlNode node1 in nodeList)
            {
                    testt = node1.OuterXml;
                     testt = testt.Replace(Environment.NewLine, string.Empty);
                    ttt.PreserveWhitespace = true;     
                    ttt.LoadXml(testt);

                    testt = testt.Replace(Environment.NewLine, string.Empty);
                   signedXml.LoadXml(ttt.DocumentElement);
                    //if (signedXml.CheckSignature(cert, true))
                    if (signedXml.CheckSignature())
                    {
                        Console.WriteLine("The XML signature is valid.");
                    }
                    else
                    {
                        Console.WriteLine("The XML signature is not valid.");
                    }


            #endregion
        }
Run Code Online (Sandbox Code Playgroud)

但他们仍然失败

我还根据xml文件制作了证书,

X509Certificate c = X509Certificate.CreateFromSignedFile("test.xml");
theCertificate = new X509Certificate2(c);
Run Code Online (Sandbox Code Playgroud)

验证,但也失败了

我真的不知道现在该做什么,我有点绝望,这是xml文件

http://puu.sh/dyqcv/356dd289ae.xml

我需要验证签名,在此之后我必须制作一个响应文件并将其发送回服务器(它已准备就绪,但因为我无法验证签名,我不想出去)

哦,是的,我已经删除了名称空间,并在签名检查/计算之前将所有内容归化

    public static XElement RemoveAllNamespaces(XElement e)
    {
        return new XElement(e.Name.LocalName,
           (from …
Run Code Online (Sandbox Code Playgroud)

c# xml validation xml-signature xml-dsig

2
推荐指数
1
解决办法
7081
查看次数

XMLDSig:我是否必须在封装签名中指定引用URI

假设我有这样的xml:

<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
    <CD>
        <TITLE>Empire Burlesque</TITLE>                    
        <ARTIST>Bob Dylan</ARTIST>
        <COUNTRY id="123">USA</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
    </CD>    
    <CD>
        <TITLE>Hide your heart</TITLE>
        <ARTIST>Bonnie Tyler</ARTIST>
        <COUNTRY>UK</COUNTRY>
        <COMPANY>CBS Records</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1988</YEAR>
    </CD>
    <CD>
        <TITLE>Greatest Hits</TITLE>
        <ARTIST>Dolly Parton</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>RCA</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1982</YEAR>
    </CD>   
</CATALOG>
Run Code Online (Sandbox Code Playgroud)

签字后我得到:

<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
    <CD>
        <TITLE>Empire Burlesque</TITLE>                    
        <ARTIST>Bob Dylan</ARTIST>
        <COUNTRY id="123">USA</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
        <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <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-md5"/>
                <ds:Reference URI="">
                    <ds:Transforms>
                        <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                        <ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
                    </ds:Transforms>
                    <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#md5"/>
                    <ds:DigestValue>C6i9GSNZ8seoXxfuFc482Q==</ds:DigestValue>
                </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue>
d/ufAnYK35PKUdi+O6DUytV+36OGAr5meHXq2qoOUp+zO1Q5HbJvIs01qlPT9oKiBEi2QiAF3Sya
ZVwi4hEI9xHkLiewmOxPo1KgVfJ1Ir2RPpkdegFYFx9QCMR4Z1M7zTkijCKv9ncWR4MYjOAfDrKf
fbvUX3AbRHlUYJj6M4QcrQUuBPhSqo4TcxtfblNqmKUT+141+sLSsuM2xy24YeyF7NUff9tirCiP
KgBHpFGtiJAdxugAlzqHaR9CP2kRA2Sg046NBo2yO/nTDfUKqquZm4aaZsLWbvKJYvrgqD4YgH4M
FFpK5ChgYa4oi7f9BAYxOFcY9f1OCHsvpdCbpw== …
Run Code Online (Sandbox Code Playgroud)

java xml xmlsec xml-signature xml-dsig

2
推荐指数
1
解决办法
6983
查看次数

在 SOAP 请求中添加 KeyInfo 引用

所以我在这里遇到了与这篇文章非常相似的问题。SOAP KeyInfo 值

我想在 KeyInfo 中添加一个引用,但似乎无法通过代码找到一种方法。

这是预期的输出应该是什么:

<KeyInfo>
    <wsse:SecurityTokenReference>
        <wsse:Reference URI="#SecurityTest" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
</KeyInfo>
Run Code Online (Sandbox Code Playgroud)

我确实在上面尝试引用的地方有这个:

<wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" 
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
        wsu:Id="SecurityTest">Base64CertStuffBlahblah
</wsse:BinarySecurityToken>
Run Code Online (Sandbox Code Playgroud)

每次创建 KeyInfo 部分的尝试都只允许我插入一个项目,比如一个键,来填充这部分,但我只想要一个参考。这段代码是我一直在使用的代码,但目前并未创建我想要的代码。

//This creates a X509 clause but it's as far as I've got. 
//The "keyInfoData" needs to be of a different type to allow custom reference?
var signer = new SignedXmlWithId(doc) {SigningKey = Key};
KeyInfo keyInfo = new KeyInfo();
KeyInfoX509Data keyInfoData = new KeyInfoX509Data();
keyInfoData.AddCertificate(cert);
keyInfo.AddClause(keyInfoData);
signer.KeyInfo = keyInfo;
Run Code Online (Sandbox Code Playgroud)

感谢您的关注,任何帮助将不胜感激。

c# xml soap xml-signature

2
推荐指数
1
解决办法
2320
查看次数

如何将存储在 HSM 中的私钥转换为 C# 中的 SignedXml.SigningKey

我正在尝试使用存储在 HSM 中的证书来实现 XML 签名的一些演示。

我从这个链接中找到了一些有趣的例子: Sign XML Document with X509Certificate2并将其修改为在 HSM 中使用证书和密钥和 PKCS11Interop 包装器。

但是任何人都可以给我一个建议或示例,将 ObjectHandle privateKey 从 HSM 转换为 SignedXML.SigningKey

private static void SignXmlWithCertificate(XmlDocument xmlDoc, X509Certificate2 cert, Session session, String alias)
        {
            SignedXml signedXml = new SignedXml(xmlDoc);

            List<ObjectAttribute> template = new List<ObjectAttribute>();
            template.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PRIVATE_KEY));
            template.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_RSA));
            template.Add(new ObjectAttribute(CKA.CKA_LABEL, alias));
            List<ObjectHandle> foundObjects = session.FindAllObjects(template);
            ObjectHandle privateKey = foundObjects[0];

            signedXml.SigningKey = privateKey; //Here is where I stuck.
Run Code Online (Sandbox Code Playgroud)

在上述外部链接的示例中。他们使用结合了私钥的证书。然后他们就可以这样使用了。

signedXml.SigningKey = cert.PrivateKey;
Run Code Online (Sandbox Code Playgroud)

但是我使用的证书里面没有私钥的内容。请给我一些建议。

c# pkcs#11 xml-signature private-key pkcs11interop

2
推荐指数
1
解决办法
2104
查看次数