给URL地址栏中的参数加密/解密
2006-06-16 18:29
471 查看
经常会看到一些网站为了安全性会对URL中的参数进行加密,也有很多朋友询问这样的问题,所以今天就贴出这么一个函数:
解密代码
<%
Function URLDecode(enStr) 'URL解碼函數
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
%>
使用方法:
mystring=server.URLEncode("要加密的字符串或变量")
解密代码
<%
Function URLDecode(enStr) 'URL解碼函數
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
%>
使用方法:
mystring=server.URLEncode("要加密的字符串或变量")
相关文章推荐
- URL地址栏中的参数加密\解密
- JS 浏览器地址栏传递参数,参数加密/解密(编码/解码)
- 使用Spring AOP对url参数进行解密以及对返回结果进行加密
- asp.net URL参数的加密与解密问题
- URL参数加密解密过程
- 学习URL传输参数加密解密
- 利用MVC的过滤器实现url的参数加密和解密
- javascript将url中的参数加密解密代码
- 对Url传输参数进行加密和解密
- 利用MVC的过滤器实现url的参数加密和解密
- 实现URL参数的加密和解密的方法 .
- js加密地址栏参数并且获解密的地址栏参数
- 实现URL参数的加密和解密的方法
- 针对url参数的加密解密算法(原创)
- WEB系统中加密/解密URL传输参数
- URL请求对参数前端JS加密,后台JAVA解密
- WEB系统中加密\解密URL传输参数(EIP.Framework中的实现)
- WEB系统中加密\解密URL传输参数.
- 今天给大家介绍一下SpringBoot框架中URL参数如何进行Base64加密解密
- 利用MVC的过滤器实现url的参数加密和解密