일반적으로 Web.config 파일의 ConnectionString에는 접속할 서버의 경로, DB명, 계정, 비밀번호 등 민감한 정보가 들어가는 경우가 많다. 따라서 반드시 암호화되어야 하는데, ASP.NET에서는 기본적으로 설정을 암호화/복호화 하는 것을 지원해준다.
먼저 IIS가 설치된 PC 혹은 VS 개발 환경에서 aspnet_regiis.exe를 실행해야 한다. 여기서는 VS2008 설치 환경을 예로 들겠다.
- 시작 - 프로그램 - Microsoft Visual Studio 2008 - Visual Studio Tools - Visual Studio 2008 명령 프롬프트 를 실행한다.
- 프롬프트에서 다음과 같이 입력한다.
aspnet_regiis.exe -pef "connectionStrings" "D:\Webapps\Sample1"
뒤의 경로는 자신의 프로젝트 경로로 지정한다. 다음과 같이 나오면 완료된 것이다.
Encrypting configuration section... Succeeded!
- 암호화된 문자열을 확인한다.
암호화 전 :
<connectionStrings> <add name="manalith_server" connectionString="Data Source=111.222.333.444;Initial Catalog=manalith;User ID=manalith;Password=test1234a" providerName="System.Data.SqlClient"/> </connectionStrings>
암호화 후 :
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider"> <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <KeyName>Rsa Key</KeyName> </KeyInfo> <CipherData> <CipherValue>...암호화된 문자열...</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>...암호화된 문자열...</CipherValue> </CipherData> </EncryptedData> </connectionStrings>
방법은 서버와 클라이언트에서 각각 암호화를 해 주거나, 조금 번거롭지만 여기에 나온 대로 별도의 키를 공유하여 사용하는 방법이 있다.