我從部署機器中得到了這個異常,這在我的開發機器中沒有發生。這是一個.net框架網站。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之一是讀取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密鑰容器,如果應用程序級別沒有權限訪問密鑰容器,它會拋出異常。那是指定的文件系統尋找?
如果是,如何解決?
我最大的問題是我不管理部署機器或IIS。即使通過,我發現了一些類似的問題解決方案,我不能只是嘗試在IIS中。在我能夠指導IT如何解決問題之前,我想了解更多信息。 https://blogs.msdn.microsoft.com/duetsupport/2012/04/06/system-security-cryptography-cryptographicexception-the-system-cannot-find-the-file-specified/ – Feng