【问题标题】:Is there a way to digitally sign a document on Medium Trust hosting?有没有办法在 Medium Trust 托管上对文档进行数字签名?
【发布时间】:2011-05-24 20:35:01
【问题描述】:

托管服务器不会执行:

SignedXml.ComputeSignature();

我认为 fromXML 和 toXML 方法需要完全信任。但这出人意料。现在不可能对任何文件进行数字签名。

在网上搜索时,我发现了这个: Using RSA Public Key Encryption in a Shared Web Hosting Environment

之前有人用过这个或者其他方法吗?

【问题讨论】:

  • 我刚刚检查了 EZRSA(你的 CodeProject 链接),它对我打算做的工作很好。但是,我必须添加对未提供的 SHA256 的支持。我已将修改后的源代码回馈给 Paul Sanders(非常感谢他)。

标签: c# digital-signature medium-trust


【解决方案1】:

我最终能够使用 Bounty Castle 安全 API 开发在线激活系统。

没有可用的直接方法,但可以使用基本 API 来生成数字签名。

【讨论】:

    【解决方案2】:

    我知道这篇文章很旧,但也许有人会觉得它有用: 该解决方案以中等信任度与 ASP .NET 3.5 配合使用:

        private XmlDocument GetSignedDoc(XmlDocument doc)
    {
          X509Certificate2 certificate = null;
                        try
                        {
                            certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + licenceFile, licenceFilePass, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
    
                            if (certificate == null)
                                throw new Exception("The certificate i
    
    s null!!!");
                    }
                    catch (Exception ex)
                    {
                        exception += "X509Certificate2 fail! Did not get certificate " + AppDomain.CurrentDomain.BaseDirectory + licenceFile;
                        exception += FormatException(ex);
                        goto SetError;
                    }
                RSACryptoServiceProvider myRSASigner = null;
    
                try
                {
                    myRSASigner = (RSACryptoServiceProvider)certificate.PrivateKey;
    
                    if (myRSASigner == null)
                    {
                        throw new Exception("No valid cert was found");
                    }
    
    
                        doc = SignXmlFile(doc, myRSASigner);
    
               catch (Exception ex)
                    {
                        exception += "SignXmlFile failed";
                        exception += FormatException(ex);
                        goto SetError;
                    }
    

    }

    private static XmlDocument SignXmlFile(XmlDocument doc, RSACryptoServiceProvider myRSA)
                {
                    byte[] sign_this = Encoding.UTF8.GetBytes(doc.InnerXml);
                    byte[] signature = myRSA.SignData(sign_this, new SHA1CryptoServiceProvider());
                    string base64_string = Convert.ToBase64String(signature);
    
                    XmlElement Signature = doc.CreateElement("Signature");
                    Signature.AppendChild(doc.CreateTextNode(base64_string));
                    doc.DocumentElement.AppendChild(doc.ImportNode(Signature, true));
    
                    return doc;
                }
    

    【讨论】:

      【解决方案3】:

      这篇文章的作者基本上是在重新发明轮子,将不同的部分组合在一起以获得一些工作代码。虽然他们的方法应该有效,并且您可以自己发明一些类似的方法(在这里和那里获取一些代码并尝试使其工作),但他们(在历史上)确认存在已修复的错误,我认为可能存在更多错误那里。

      JFYI:我们提供XML security components,它可以在有限的环境中工作,因为我们自己编写了所有代码并包含在我们的程序集中。

      【讨论】:

      • @Aseem 请确保您已单独检查过 XMLBlackbox 包的价格 - 这是相当合理的。
      猜你喜欢
      • 2020-12-12
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      相关资源
      最近更新 更多