3초기억력

ASP - CAPICOM 활용한 암호화/ 복호화 ASP 코딩 본문

플밍_ASP

ASP - CAPICOM 활용한 암호화/ 복호화 ASP 코딩

잠수콩 2011. 8. 29. 09:46



제목 :  ASP - CAPICOM 활용한 암호화/ 복호화 ASP 코딩


암호화

<%
Const CAPICOM_ENCRYPTION_ALGORITHM_RC2 = 0 ' Use RSA RC2 encryption.
Const CAPICOM_ENCRYPTION_ALGORITHM_RC4 = 1 ' Use RSA RC4 encryption.
Const CAPICOM_ENCRYPTION_ALGORITHM_DES = 2 ' Use DES encryption.
Const CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3 ' Use triple DES encryption.

strTestMessage = "Hello World!"
strPassphrase = "A#0x?\$dE<" ' NIEMALS die Passphrase "herumliegen" lassen

Set xEncrypt = Server.CreateObject("CAPICOM.EncryptedData")
xEncrypt.Content = strTestMessage
xEncrypt.SetSecret strPassphrase
xEncrypt.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_3DES
strEncryptedMsg = xEncrypt.Encrypt()

Response.Write strEncryptedMsg
%>
 



복호화
<%
Const CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3 ' Use triple DES encryption.

strCipherText = "MGoGCSsGAQQBgjdYA6BdMFsGCisGAQQBgjdYAwGgTTBLAgMBAAACAmYDAgIAwAQI" & vbCrlf & _
   "JZjDl4H5hRIEEOdot2WroaM35Vr5FVAl/e8EIL7qaJJeuMBQC4625aKdH8u8hgd5" & vbCrlf & _
   "rsyBD3jAok7fbdCG"

strPassphrase = "A#0x?\$dE<" ' NIEMALS die Passphrase "herumliegen" lassen

Set xEncrypt = Server.CreateObject("CAPICOM.EncryptedData")
xEncrypt.SetSecret strPassphrase
xEncrypt.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_3DES
xEncrypt.Decrypt(strCipherText)
strPlainText = xEncrypt.Content

Response.Write strPlainText
%>



고도 암호화?

<%
Const CAPICOM_ENCRYPTION_ALGORITHM_RC2 = 0 ' Use RSA RC2 encryption.
Const CAPICOM_ENCRYPTION_ALGORITHM_RC4 = 1 ' Use RSA RC4 encryption.
Const CAPICOM_ENCRYPTION_ALGORITHM_DES = 2 ' Use DES encryption.
Const CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3 ' Use triple DES encryption.
Const CAPICOM_KEY_LENGTH_MAXIMUM = 0 ' Use the maximum key length available with the indicated encryption algorithm.
Const CAPICOM_KEY_LENGTH_40_BITS = 1 ' Use 40-bit keys.
Const CAPICOM_KEY_LENGTH_56_BITS = 2 ' Use 56-bit keys if available.
Const CAPICOM_KEY_LENGTH_128_BITS = 3 ' Use 128-bit keys if available

strTestMessage = "Hello World!"
strPassphrase = "A#0x?\$dE<" ' NIEMALS die Passphrase "herumliegen" lassen

Set xEncrypt = Server.CreateObject("CAPICOM.EncryptedData")
xEncrypt.Content = strTestMessage
xEncrypt.SetSecret strPassphrase

' Key lengths for DES and 3DES encryption are standard and the key length
' property is ignored when these algorithms are used.
xEncrypt.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_RC4
xEncrypt.Algorithm.KeyLength = CAPICOM_KEY_LENGTH_128_BITS

strEncryptedMsg = xEncrypt.Encrypt()

Response.Write strEncryptedMsg
%>





내용 : CAPICOM 을 사용한 암호화/ 복호화 기법. CAPICOM.DLL 을 시스템 레지스트리에 설치를 한 후 사용가능하다.

웹 호스팅쪽에는 관리자에게 설치를 요구하거나 해야 사용할 수 있다.

서버호스팅을 직접하는경우는 서버 관리자에게 문의~~

변수명 : strPassphrase의 값이 동일해야 복호화가 에러없이 진행된다.


출처 : http://www.aspheute.com/artikel/20020115.htm

http://www.microsoft.com/ko-kr/download/details.aspx?id=25281


첨부한 CAPICOM.DLL 은 MS홈페이지에서 다운로드한것이고, SAMPLE_ENCRYPT.ZIP 파일은 출처 URL에서 DOWNLOAD 한 것


Comments