ASP没有内置的加密解密函数,导致我们在做AJAX传递参数的时候容易出现乱码,下面跟大家分享:ASP自定义escape加密和unescape解密函数。
Function vbsEscape(str)'加密<br> dim i,s,c,a<br> s=""<br> For i=1 to Len(str)<br> c=Mid(str,i,1)<br> a=ASCW(c)<br> If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then<br> s = s & c<br> ElseIf InStr("@*_+-./",c)>0 Then<br> s = s & c<br> ElseIf a>0 and a<16 Then<br> s = s & "%0" & Hex(a)<br> ElseIf a>=16 and a<256 Then<br> s = s & "%" & Hex(a)<br> Else<br> s = s & "%u" & Hex(a)<br> End If<br> Next<br> vbsEscape = s<br> End Function
Function vbsUnEscape(str)'解密<br> dim i,s,c<br> s=""<br> For i=1 to Len(str)<br> c=Mid(str,i,1)<br> If Mid(str,i,2)="%u" and i<=Len(str)-5 Then<br> If IsNumeric("&H" & Mid(str,i+2,4)) Then<br> s = s & CHRW(CInt("&H" & Mid(str,i+2,4)))<br> i = i+5<br> Else<br> s = s & c<br> End If<br> ElseIf c="%" and i<=Len(str)-2 Then<br> If IsNumeric("&H" & Mid(str,i+1,2)) Then<br> s = s & CHRW(CInt("&H" & Mid(str,i+1,2)))<br> i = i+2<br> Else<br> s = s & c<br> End If<br> Else<br> s = s & c<br> End If<br> Next<br> vbsUnEscape = s<br> End Function