일반적으로 Web.config 파일의 ConnectionString에는 접속할 서버의 경로, DB명, 계정, 비밀번호 등 민감한 정보가 들어가는 경우가 많다. 따라서 반드시 암호화되어야 하는데, ASP.NET에서는 기본적으로 설정을 암호화/복호화 하는 것을 지원해준다.

먼저 IIS가 설치된 PC 혹은 VS 개발 환경에서 aspnet_regiis.exe를 실행해야 한다. 여기서는 VS2008 설치 환경을 예로 들겠다.

  1. 시작 - 프로그램 - Microsoft Visual Studio 2008 - Visual Studio Tools - Visual Studio 2008 명령 프롬프트 를 실행한다.
  2. 프롬프트에서 다음과 같이 입력한다.
    aspnet_regiis.exe -pef "connectionStrings" "D:\Webapps\Sample1"
    뒤의 경로는 자신의 프로젝트 경로로 지정한다. 다음과 같이 나오면 완료된 것이다.
    Encrypting configuration section...
    Succeeded!
  3. 암호화된 문자열을 확인한다.
    암호화 전 :
    <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>
      

성공적으로 암호화되었고 접속도 잘 된다. 그러나 이 경우 한 가지 문제가 있는데, 바로 이 Web.config 파일을 어느곳에서나 사용할 수 없다는 것이다. 이 파일을 그대로 서버에 올리고 사용하면 ASPX 페이지는 암호화된 문자열을 해독할 수 없다는 에러 메시지를 띄운다. 사용하는 키가 다르기 때문이다.

방법은 서버와 클라이언트에서 각각 암호화를 해 주거나, 조금 번거롭지만 [http]여기에 나온 대로 별도의 키를 공유하여 사용하는 방법이 있다.

powered by Moniwiki | themed by clockoon
last modified 2009-06-09 00:50:23
Processing time 0.0122 sec