2010-05-31 3 views
1

LINQ TO SQL을 사용할 때 web.config 파일의 connectionStrings 섹션을 암호화하는 가장 좋은 방법은 무엇입니까? 당신이 그렇게 할 필요를 느끼는 경우Linq to SQL을 사용할 때 연결 문자열 암호화

+0

이게 전부 필요합니까? IIS는 Web.config를 제공하지 않으므로 서버를 손상시키지 않는 한 아무도 읽을 수 없습니다. 여전히 걱정이된다면 RijndaelManaged를 사용하여 설정에서 문자열을 암호화 한 다음 LINQ가 감동하기 전에 해독 할 클래스를 생성 할 수 있습니다. http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx –

답변

3

첫째, Web.config의에서 암호화 섹션 /의 app.config는 특정하지 않습니다 Linq2Sql. .NET 프레임 워크에는 web.config/app.config의 일부를 독립적으로 암호화/해독 할 수있는 특수 클래스 세트가 함께 제공됩니다.

DPAPI 공급자를 사용하여 web.config의 섹션을 암호화 할 수 있습니다. 응용 프로그램을 변경할 필요가 없습니다. 당신은 여전히 ​​appsettings 및 conn 읽기 계속. 문자열은 평소대로. 아래의이 코드를 사용하여 설정 파일의 일부를 암호화/해독하십시오.

//call: ProtectSection("connectionStrings","DataProtectionConfigurationProvider"); 
private void ProtectSection(string sectionName, string provider) 
{ 
    Configuration config = 
     WebConfigurationManager. 
      OpenWebConfiguration(Request.ApplicationPath); 

    ConfigurationSection section = config.GetSection(sectionName); 

    if (section != null && !section.SectionInformation.IsProtected) 
    { 
     section.SectionInformation.ProtectSection(provider); 
     config.Save(); 
    } 
} 

//call: UnProtectSection("connectionStrings"); 
private void UnProtectSection(string sectionName) 
{ 
    Configuration config = 
     WebConfigurationManager. 
      OpenWebConfiguration(Request.ApplicationPath); 

    ConfigurationSection section = config.GetSection(sectionName); 

    if (section != null && section.SectionInformation.IsProtected) 
    { 
     section.SectionInformation.UnprotectSection(); 
     config.Save(); 
    } 
} 
+1

또는 내장 된 aspnet_regiis 유틸리티를 사용하여 .NET 구성 파일 섹션을 암호화/암호 해독하십시오. –

+0

encryption using DPAPI는 로컬 컴퓨터에만 적용되는 로컬 machineKey를 사용합니다. 서버에 응용 프로그램을 배포 할 때 서버의 aspnet_regiis 도구에 액세스 할 수 없거나 web.config/app.config에 machineKey 섹션을 제공해야 할 수도 있습니다. 그래서 코드로 할 것을 권하고 싶습니다. –

1

, 당신은 단지 당신의 web.config 파일의 <connectionStrings> 섹션을 암호화 할 수 있습니다 - 그것은 표준 .NET 절차, 그것은 처리 할 수있는 모든 .NET 코드 - 아무런 문제 :

또는 그것을위한 구글이나 빙 - 당신이 히트의 수천을 얻을 것이다 ..... 모든

관련 문제