私の開発マシンでは発生しなかった展開マシンからこの例外を受け取りました。これは .net フレームワークの Web サイトです。
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 ファイルを読み取っています。github でその SDK コードを調べると、次のようになります。
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 キー コンテナを作成し、アプリケーション レベルでキー コンテナに正しくアクセスできない場合、例外をスローします。それは、指定されたファイル システムが探しているものですか?
はいの場合、それを修正する方法は?