Microsoft EnterpriseLibrary 암호화에  파일을 참조합니다.

라이브러리 참고  및 다운로드 사이트

http://msdn.microsoft.com/en-us/library/dd203099.aspx

 

시작

image

 

 

Microsoft EnterpriseLibrary 설치되면

image

위의 그림처럼 UI 형태로 수정할수 있는 화면을 볼수 있습니다.

 

 

마우스 오른쪽을 클릭해서 Cryptography Application Block 을 추가합니다.

image

 

 

Symmetric Providers 에서 마우스 오른쪽으로 New 클릭

image

 

오케이

image

암호화 키를 만들어 줍니다.

 

image

Generate 클릭

 

 image

 

image

 

 

키를 저장할 위치설정

 

 

 

image

현재 사용자만 엑세스 할껀지 전부가능할껀지 선택

 

image

 

완료

만들고 나면 WEB.CONFIG 에는 아래와 같은 코드가 만들어집니다.

 

<securityCryptographyConfiguration>
  <symmetricCryptoProviders>
    <add algorithmType="System.Security.Cryptography.RijndaelManaged, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
      protectedKeyFilename="파일위치\Test.key"
      protectedKeyProtectionScope="CurrentUser" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.SymmetricAlgorithmProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="RijndaelManaged" />
  </symmetricCryptoProviders>
</securityCryptographyConfiguration>

 

 

 

코드상에서 실제로 사용하기

image

 

RijndaelManaged 라는 이름으로 만들었으므로

using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

public static string Encrypt(string dataToEncrtypt)
{
    string encryptedData = Cryptographer.EncryptSymmetric("RijndaelManaged", dataToEncrtypt);
    return encryptedData;
}

public static string Decrypt(string cipheredString)
{
    string decryptedString = Cryptographer.DecryptSymmetric("RijndaelManaged", cipheredString);
    return decryptedString;
}

 

 

참고로 이파일을 들고 다른피시에서 똑같이 복사해도(암호화키 가지고 가서도)

암호화 키가 달라서  같은 해독되지 않습니다.

+ Recent posts