SignedXml.CheckSignatureメソッドを使用して署名付きXML文書から暗号鍵を取得し、その署名をチェックする小さな方法を開発しました。暗号化ライセンスモジュールがWebサイトから機能していませんか?
コマンドラインアプリから実行すると、キーが正しく検証されます。しかし、私はそれをWebアプリケーションから呼び出すとすぐに動作を停止します。誰もが、私はウェブサーバは、コマンドラインツールよりも、別のユーザーとして実行されることを推測起こって何ができるか?:
// Verify the signature of an XML file against an asymmetric
// algorithm and return the result.XmlDocument Doc, RSA Key
public static Boolean VerifyLicenceFile(string xmlLicFilePathArg)
{
bool isVerified = false;
try
{
CspParameters cspParams = new CspParameters();
cspParams.KeyContainerName = containerName;
RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);
// Create a new XML document.
XmlDocument xmlDoc = new XmlDocument();
// Load an XML file into the XmlDocument object.
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(xmlLicFilePathArg);
// Check arguments.
if (xmlDoc == null)
throw new ArgumentException("Doc");
if (rsaKey == null)
throw new ArgumentException("Key");
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml(xmlDoc);
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// This example only supports one signature for
// the entire XML document. Throw an exception
// if more than one signature was found.
if (nodeList.Count >= 2)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
isVerified = signedXml.CheckSignature(rsaKey);
}
catch (Exception ex)
{
}
return isVerified;
}
OK、エラーは何ですか? 「働くのを止める」とはどういう意味ですか? pathArgsはどこから来たのですか? –
こんにちはすみませんでした。 '停止する'とは、isVerified値が偽であることを意味します。エラーはなく、何が起こっているのかは分かりません。私は実際にC#クラス(明らかに)のいずれかに入ることはできませんので、わかりません。 pathArgは、確実に存在し、コマンドラインから呼び出されたときに確実に動作するライセンスファイルへのパスです。 – Exitos
ConsaoleとASPの両方のアプリケーションが同じPC上で動作しますか? –