3

データベースに保存された証明書 (公開鍵と秘密鍵) を使用して xml ファイルに署名するアプリを作成しようとしています。

私が抱えている問題は、(データベースからではなく) ファイルから pfx ファイルをロードするたびに、次を使用して xml の署名を計算しようとすることです。

var cert = new X509Certificate2(@"c:\temp\cert.pfx");
var signedXml = new SignedXml(doc) {SigningKey = cert};
signedXml.ComputeSignature();

次の例外が発生します。

An exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll but was not handled in user code

Additional information: The system cannot find the file specified.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 cbHash, ObjectHandleOnStack retSignature)
at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash)
at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, Int32 calgHash)
at System.Security.Cryptography.RSAPKCS1SignatureFormatter.CreateSignature(Byte[] rgbHash)
at System.Security.Cryptography.Xml.SignedXml.ComputeSignature()
<snip>
... my code
</snip>

以下を使用して pfx を作成しました。

makecert -r -pe -n "CN=CompanyXYZ Server" -b 01/01/2007 -e 01/01/2010 -sky exchange Server.cer -sv Server.pvk
pvk2pfx.exe -pvk Server.pvk -spc Server.cer -pfx Server.pfx

これをさらに明確にするために。ASP.NET Web サイトで使用されていますが、「ユーザー プロファイルの読み込み」を true に設定できません。

4

0 に答える 0