2010-12-02 13 views
0

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; 

    } 
+0

OK、エラーは何ですか? 「働くのを止める」とはどういう意味ですか? pathArgsはどこから来たのですか? –

+0

こんにちはすみませんでした。 '停止する'とは、isVerified値が偽であることを意味します。エラーはなく、何が起こっているのかは分かりません。私は実際にC#クラス(明らかに)のいずれかに入ることはできませんので、わかりません。 pathArgは、確実に存在し、コマンドラインから呼び出されたときに確実に動作するライセンスファイルへのパスです。 – Exitos

+0

ConsaoleとASPの両方のアプリケーションが同じPC上で動作しますか? –

答えて

1

を知っています。 CspProviderFlags.UseMachineKeyStoreを使用しない限り、CspParametersはデフォルトでユーザーキーストアを使用します。 RsaCryptoServiceProviderは、指定されたキーコンテナが存在しない場合、新しいキーを自動的に生成します。その結果、コマンドラインから実行しているときとは異なるコードをWebサーバーで実行するときに確認します。

+0

こんにちは、これを試してみましたが残念ながら:-( – Exitos

+0

@ Pete2k:データに署名するキーが次のものと同じであることを確認する必要があります。 rsaKey.ToXmlString(false)をログに記録することができます。署名して同じキーを使用していないことを確認する文字列が一致しない限り、 –

+0

これを試してみてください。 – Exitos

関連する問題