如何使用USB令牌和capicom工具在ASP.NET中对XML文件进行数字签名?

时间:2015-01-30 05:24:33

标签: javascript c# asp.net digital-signature capicom

我想知道如何使用USB令牌在ASP.NET C#中对XML文件进行数字签名?

我想知道如何从mosearbear USB令牌获取证书并使用其中包含的私钥对XML文件进行数字签名

由于 USB在客户端计算机上,我想在客户端系统上签署XMl文件,那么如何做到这一点?

我所知道的是不容易在客户端计算机上访问设备,但是 我已经知道它可以用capicom完成,但不要“知道如何

我最近得知的是微软停止使用capicom。那又有什么选择?

我有一些代码,但这似乎不是我想要的。任何人都可以帮助我吗?

X509Store store = new X509Store(StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        X509CertificateCollection certificates =  X509Certificate2UI.SelectFromCollection(store.Certificates,
                                                                                        "Certificados conocidos",
                                                                                        "Por favor seleccione el certificado con el cual desea firmar",
                                                                                        X509SelectionFlag.SingleSelection
                                                                                        );
        store.Close();
        X509Certificate2 certificate = null;
        if (certificates.Count != 0)
        {
            //The selected certificate
            certificate = (X509Certificate2)certificates[0];
        }
        else
        {
            //The user didn't select a certificate
            //return "El usuario canceló la selección de un certificado";
        }
        //Check certificate's atributes to identify the type of certificate (censored)
        if (certificate.Issuer != "CN=............................., OU=................., O=..., C=US")
        {
            //The selected certificate is not of the needed type
           // return "El certificado seleccionado no corresponde a un token ...";
        }
        //Check if the certificate is issued to the current user
        //if (!certificate.Subject.ToUpper().Contains(("E=" + pUserADLogin + "@censoreddomain.com").ToUpper()))
        //{
        //    //return "El certificado seleccionado no corresponde al usuario actual";
        //}
        //Check if the token is currently plugged in
        XmlDocument xmlDoc = new XmlDocument();
        //XmlElement element = xmlDoc.CreateElement("Content", SignedXml.XmlDsigNamespaceUrl.ToString());
        //element.InnerText = "comodin";
       // xmlDoc.AppendChild(element);
        SignedXml signedXml = new SignedXml();
        //try
        //{
        //    signedXml.SigningKey = certificate.PrivateKey;
        //}
        //catch
        //{
        //    //USB Token is not plugged in
        //   // return "El token no se encuentra conectado al equipo";
        //}
        //DataObject dataObject = new DataObject();
        //dataObject.Data = xmlDoc.ChildNodes;
        //dataObject.Id = "CONTENT";
        //signedXml.AddObject(dataObject);
        //Reference reference = new Reference();
        //reference.Uri = "#CONTENT";
        //signedXml.AddReference(reference);
        //Attempt to sign the data. The user will be prompted to enter his PIN
        try
        {
           // signedXml.ComputeSignature();
        }
        catch
        {
            //User didn't enter the correct PIN
           // return "Hubo un error confirmando la identidad del usuario";
        }
        // The user has signed with the correct token

0 个答案:

没有答案