2016-12-10 63 views
0

我從部署機器中得到了這個異常,這在我的開發機器中沒有發生。這是一個.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密鑰容器,如果應用程序級別沒有權限訪問密鑰容器,它會拋出異常。那是指定的文件系統尋找?

如果是,如何解決?

+0

我最大的問題是我不管理部署機器或IIS。即使通過,我發現了一些類似的問題解決方案,我不能只是嘗試在IIS中。在我能夠指導IT如何解決問題之前,我想了解更多信息。 https://blogs.msdn.microsoft.com/duetsupport/2012/04/06/system-security-cryptography-cryptographicexception-the-system-cannot-find-the-file-specified/ – Feng

回答

0

我們在辦公室有類似的問題。最近的組策略更新從%ProgramData%\Microsoft\Crypto\RSA\MachineKeys文件夾中刪除了權限。我們的應用程序正在使用BouncyCastle創建一個自簽名證書。在策略更新之前安裝應用程序的用戶可以繼續運行應用程序。更新後安裝應用程序的用戶無法運行應用程序。使用Process Monitor幫助我們識別發生了什麼(使用Windows資源管理器,我們可以看到創建的文件,但應用程序沒有list folder contents)。

此組策略更新推動使硬盤加密勒索軟件應用程序無法創建加密驅動器所需的密鑰。我們將致力於解決此問題的永久性解決方案,以滿足我們安全部門的政策。

相關問題