私の開発マシンでは発生しなかったこの例外がデプロイメントマシンから発生しました。これは.NET FrameworkのWebサイトです。System.Security.Cryptography.CryptographicException:指定されたファイルが見つかりません
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv)
at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
at Org.BouncyCastle.Security.DotNetUtilities.CreateRSAProvider(RSAParameters rp)
at Box.V2.JWTAuth.BoxJWTAuth..ctor(IBoxConfig boxConfig)
私のケースは、ウェブサイトで使用されているSDKの1つで、RSA private_keys.pemファイルを読み込んでいます。そのSDKコードをgithubで探してみましょう:
var pwf = new PEMPasswordFinder(this.boxConfig.JWTPrivateKeyPassword);
AsymmetricCipherKeyPair key;
using (var reader = new StringReader(this.boxConfig.JWTPrivateKey))
{
key = (AsymmetricCipherKeyPair)new PemReader(reader, pwf).ReadObject();
}
var rsa = DotNetUtilities.ToRSA((RsaPrivateCrtKeyParameters)key.Private);
SDKは開発マシンでは問題なく動作しますが、デプロイメントマシンでは問題ありません。 指定したファイルが見つからない場合、私はprivate_key.pemファイルではないと思います。
だから、私はCryptogrphyのことがどのようにうまくいくかを調べようとしています。 ここに私が見つけたものは、間違っていれば何かを指摘します。 cryptoAPIのように見えますが、RSAキーコンテナを作成し、アプリケーションレベルでキーコンテナへのアクセス権がない場合は例外がスローされます。それは指定されたファイルシステムを探していますか?
はいの場合は、どのように修正するのですか?
私の最大の問題は、私が配備マシンやIISを管理していないことです。でも、私はいくつかの同様の問題の解決策を見つけた、私はちょうどIISで試してみることはできません。私は問題を解決する方法をIT担当者に伝える前に、もっと学びたいと思っています。 https://blogs.msdn.microsoft.com/duetsupport/2012/04/06/system-security-cryptography-cryptographicexception-the-system-cannot-find-the-file-specified/ – Feng