2017-08-04 1 views
-4

私はmvcプロジェクトでRSAの実装にhttps://github.com/jrnker/CSharp-easy-RSA-PEMを使用しました。RSAをCSharp-easy-RSA-PEM経由で使用している場合のサーバー上の例外の取得

IISのローカルマシンでも正常に動作しています& Visual Studioでもアプリケーションをサーバーに配備すると、以下の例外が発生します。

"System.NullReferenceException: Object reference not set to an instance of an object.\r\n at CoreEntities.Classes.Utility.RSADecrypt(String input)\r\n at WebAPI.Attributes.ApiAuthorizeAttribute.Authorize(HttpActionContext actionContext)" 

私のコードです:私は多くのことをデバッグした後https://github.com/jrnker/CSharp-easy-RSA-PEM/issues/8

@もgithubの上の私の問題を掲載

public static string RSADecrypt(string input) 
{ 
    try 
    { 
     string priv = File.ReadAllText(HostingEnvironment.MapPath("~/Certificates/consumer.pem")); 
     RSACryptoServiceProvider privc = Crypto.DecodeRsaPrivateKey(priv); 
     return Crypto.DecryptString(input, privc); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 

、私はシステムがRSACryptoServiceProvider

のオブジェクトを作成していないことを考え出しました
CspParameters parms = new CspParameters(); 
parms.Flags = CspProviderFlags.NoFlags; 
parms.KeyContainerName = Guid.NewGuid().ToString().ToUpperInvariant(); 
parms.ProviderType = ((Environment.OSVersion.Version.Major > 5) || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1))) ? 0x18 : 1; 

// Exception is comping in below line. 
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(parms); 

RSAParameters rsAparams = new RSAParameters(); 

例外: - System.Security.Cryptography.CryptographicException: The system cannot find the file specified.\r\n\r\n at CoreEntities.Classes.Utility.RSADecrypt(String input)\r\n at WebAPI.Attributes.ApiAuthorizeAttribute.Authorize(HttpActionContext actionContext) 誰でも助けてください...

+0

は誰PEM /パブファイルを使用してRSAを実装する方法を知らないようです。 –

答えて

0

@Downvoters、親切に注意してください。

この問題の解決策が見つかりました。

この問題は、主にWindows Server 2008以降に組み込まれた新しいセキュリティの制約が原因です。

Windows server 2008では、デフォルトでCryptoGraphic Operatorという名前の新しいユーザーが作成されます。

あなたはWindows Server 2008のIIS7下記従っ

  1. 作成した仮想ディレクトリのそれぞれのアプリケーションプールを実行しているアカウントすべきステップでアプリケーションをホストすることを決定したとき、アプリケーションがRSACryptoServiceProviderを使用している場合はCryptoGraphic Operatorユーザーに追加することができます。
  2. IIS7 - > ApplicationPools - > YourAppPool - > RighClikck - >詳細設定--->ユーザープロファイルをロードすると、この値がtrueに設定されます。

これは私の問題を解決しました。

参考: - https://social.msdn.microsoft.com/Forums/vstudio/en-US/ec93922a-fd1e-4225-b5cf-1472ebb3acd1/systemsecuritycryptographycryptographicexception-the-system-cannot-find-the-file-specified?forum=netfxbcl

関連する問題