2017-09-28 17 views
0

私はC#コードに接続文字列を持っているので、ストアドプロシージャを使用してデータベースからデータを取得できます。C#コードで接続文字列を暗号化

接続文字列は、このようなものです:

connection.ConnectionString = "Data Source=192.168.4.33;Initial Catalog=database;Persist Security Info=True;User ID=test;[email protected]"; 

どのように私は接続を暗号化することができ、その後、私はそれが解読使いたいとき?

+0

RijndaelManagedを使用して、接続文字列を暗号化/復号化することができます。 – mbadeveloper

+0

Googleで回答が見つかりませんでしたか?これは本当によく文書化されています。それともXamarinのために問題なのですか? – smoore4

+0

Googleでは、web.configで接続文字列を暗号化することについて話しています。 – Phill

答えて

0

あなたは、この使用することができます:RSAProtectedConfigurationProviderまたはDPAPIProtectedConfigurationProviderを使用して暗号化を実行するために

try 
{ 
    // Open the configuration file and retrieve 
    // the connectionStrings section. 
    Configuration config = ConfigurationManager. 
     OpenExeConfiguration(exeConfigName); 

    ConnectionStringsSection section = 
     config.GetSection("connectionStrings") 
     as ConnectionStringsSection; 

    if (section.SectionInformation.IsProtected) 
    { 
     // Remove encryption. 
     section.SectionInformation.UnprotectSection(); 
    } 
    else 
    { 
     // Encrypt the section. 
     section.SectionInformation.ProtectSection(
      "DataProtectionConfigurationProvider"); 
    } 
    // Save the current configuration. 
    config.Save(); 

    Console.WriteLine("Protected={0}", 
     section.SectionInformation.IsProtected); 
} 
catch (Exception ex) 
{ 
    Console.WriteLine(ex.Message); 
} 

たりエンタープライズライブラリデータアクセスアプリケーションブロックを。 リンク: http://msdn.microsoft.com/en-us/library/89211k9b(VS.80).aspx

+0

これはweb.configファイルを使用している場合です – Phill

関連する問題