託管服務器只是不會執行:有沒有辦法在Medium Trust託管上對文檔進行數字簽名?
SignedXml.ComputeSignature();
我認爲需要fromXML和方法toxml用於完全信任。但這令人驚訝。現在不可能對任何文檔進行數字簽名。
上搜索,我發現這個網: Using RSA Public Key Encryption in a Shared Web Hosting Environment
任何人使用此之前或任何其他方式?
託管服務器只是不會執行:有沒有辦法在Medium Trust託管上對文檔進行數字簽名?
SignedXml.ComputeSignature();
我認爲需要fromXML和方法toxml用於完全信任。但這令人驚訝。現在不可能對任何文檔進行數字簽名。
上搜索,我發現這個網: Using RSA Public Key Encryption in a Shared Web Hosting Environment
任何人使用此之前或任何其他方式?
我最終能開發利用Bounty Castle安全API的在線激活系統。
沒有可用的一個直接的方法,但基本的API可以被用於產生一個數字簽名。
文章的作者是通過以獲得一些工作的代碼變得不同拼湊基本上重新發明輪子。雖然他們的方法應該工作,你可以自己發明一些類似的方法(在這裏和那裏採取一些代碼,並試圖使其工作),他們確認(在歷史上),有已修復的錯誤,我以爲可以有更多的bug那裏。
JFYI:我們提供XML security components在有限的環境,因爲我們都寫的代碼自己,包括在我們的組件,其工作。
謝謝,但價格現在不適合我。 – 2010-12-13 18:58:07
@Aseem確保您已經單獨檢查了XMLBlackbox包的價格 - 這是非常合理的。 – 2010-12-13 19:27:45
我知道這個職位是舊的,但也許有人會發現它有用:
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;
}
我剛剛檢查: 解決方案與ASP .NET 3.5中的中等信任的工作原理出EZRSA(你的CodeProject的鏈接),它爲我打算做的很好。但是,我不得不添加對SHA256的支持,而這是沒有提供的。我將修改過的源代碼貢獻給Paul Sanders(非常感謝他)。 – 2011-03-14 21:34:48