ACTIVE SERVER PAGE > 간단한 암호화 / 복호화 로직
등록일 : 2017-07-04 17:46
조회수 : 93,696
ASP로 만들어 보는 간단한 암호화 복호화 로직 입니다.
회원의 아이디, 패스워드등을 DB에 저장할 때 암호화 하여 저장을 하게 됩니다. 그리고 회원이 로그인을 하게 되면
복호화 하여 회원이 입력한 문자열과 비교하여 로그인 여부등을 체킹할수 있습니다.
Const Ref = "D7EFGBCHL640MN598OIJKPQRSATWXVYZ123U"
' 암호화
Function encode(str,chipVal)
Dim Temp, TempChar, Conv, Cipher, i : Temp = ""
chipVal = CInt(chipVal)
str = StringToHex(str)
for i = 0 to len(str) - 1
TempChar = Mid(str,i+1,1)
Conv = InStr(Ref,TempChar)-1
Cipher = Conv Xor chipVal
Cipher = Mid(Ref,Cipher+1,1)
Temp = Temp + Cipher
next
encode = Temp
End Function
' 복호화
Function decode(str,chipVal)
Dim Temp, TempChar, Conv, Cipher, i : Temp = ""
chipVal = CInt(chipVal)
for i = 0 to len(str) - 1
TempChar = Mid(str,i+1,1)
Conv = InStr(Ref,TempChar)-1
Cipher = Conv Xor chipVal
Cipher = Mid(Ref,Cipher+1,1)
Temp = Temp + Cipher
next
Temp = HexToString(Temp)
decode = Temp
End Function
' 문자열 -> 16진수
Function StringToHex(pStr)
dim i, one_hex, retVal
for i = 1 to len(pStr)
one_hex = hex(asc(mid(pStr,i,1)))
retVal = retVal & one_hex
next
StringToHex = retVal
End Function
' 16진수 -> 문자열
Function HexToString(pHex)
dim one_hex, tmp_hex, i, retVal
for i = 1 to len(pHex)
one_hex = mid(pHex,i,1)
if IsNumeric(one_hex) then
tmp_hex = mid(pHex,i,2)
i = i + 1
else
tmp_hex = mid(pHex,i,4)
i = i + 3
end if
retVal = retVal & chr("&H" & tmp_hex)
next
HexToString = retVal
End Function
en1 = encode("761541-5425486 : 이상한 사람이다.... ㅎㅎㅎㅎ !@#$%^&*()",2)
en2 = decode(en1,2)
Response.write en1 &"<br>"& en2
혹시 사용할 일이 있으시면 사용하세요.