%
Dim str
str = "gM+PvNyZicc156IlrFvrzHKcpmIjXHWIDxKy54ufpJy5U/6tHJ0mOlyoD+fLDIin5iiLRQeP7tDe4C+w/ThyMg=="
Dim aes
Set aes = new AesClass
With aes
.Key = "V1Pk9qtHoNSXZ4JF5N7aHekgz9lWamO7OXFAv3JUWK4"
.IV = "c6MwehOlbmn1T6P92OchJBsLm2l" 'cbc mode only
.Mode = "cbc"
.Padding = "pkcs5"
.Encoding = "gb2312"
'Response.Write .Encode(str) & "
"
Response.Write .Decode(str)
End With
Class AesClass
Private sKey, sIV, sMode, sPadding, sEncoding
Private Rcon, S, T1, T2, T3, T4
Private S5, T5, T6, T7, T8, U1, U2, U3, U4
Private Rounds
Public Property Let Key(ByVal strKey)
sKey = strKey
End Property
Public Property Let IV(ByVal strIV)
sIV = strIV
End Property
Public Property Let Mode(ByVal strMode)
sMode = LCase(strMode)
End Property
Public Property Let Padding(ByVal strPadding)
sPadding = LCase(strPadding)
End Property
Public Property Let Encoding(ByVal strEncoding)
sEncoding = LCase(strEncoding)
End Property
'//¼ÓÃÜÖ÷º¯Êý;
Public Default Function Encode(ByVal str)
Encode = bin2hex(AesEncode(str))
End Function
'//½âÃÜÖ÷º¯Êý;
Public Function Decode(ByVal str)
Decode = AesDecode(hex2bin(str))
End Function
'//¼ÓÃܹ¦Äܺ¯Êý;
Private Function AesEncode(ByVal str)
Dim lens, m, r, i, eKey
Dim pdcnt, pdstr, iv
Dim CB, PB, PT(3), sResult
m = 0 : str = str2bin(str) : lens = LenB(str)
'//¼ÓÃÜÌî³ä;
'/////////////////////////////////////////////
pdcnt = 16 - (lens Mod 16)
If sPadding = "pkcs5" Then
pdstr = str2bin(String(pdcnt,pdcnt))
If pdcnt = 16 Then lens = lens + 16
ElseIf sPadding = "none" Then
If pdcnt<>16 Then
Response.write("NoneÌî³äģʽҪÇó±»¼ÓÃÜ×Ö·û´®³¤¶È±ØÐëΪ16×Ö½ÚµÄÕûÊý±¶!")
Exit Function
End If
ElseIf sPadding = "zero" Then
If pdcnt<16 Then pdstr = str2bin(String(pdcnt,0))
End If
str = str & pdstr
'/////////////////////////////////////////////
eKey = keyExpansion(sKey,"en")
'//CBCģʽ;
If sMode = "cbc" Then
iv = str2bin(sIV) : CB = PackBytes(iv, m) : m=0
End If
While m 8 Then
For j=1 To kc-1
tk(j) = tk(j) Xor tk(j-1)
Next
Else
For j=1 To (kc/2) -1
tk(j) = tk(j) Xor tk(j-1)
Next
temp = tk(kc/2-1)
tk(kc/2) = tk(kc/2) Xor (S(B0(temp)) Or SHL(S(B1(temp)),8) Or SHL(S(B2(temp)),16) Or SHL(S(B3(temp)),24))
For j=kc/2+1 To kc-1
tk(j) = tk(j) Xor tk(j-1)
Next
End If
j = 0
While (j=2^31 Or Num<-(2^31) Then
Err.Raise 6 : Exit Function
End If
If Abs(iCL) >= 32 Then iCL = iCL - Fix(iCL/32)*32
If iCL<0 Then iCL = iCL + 32
Dim i, Mask
For i=1 To iCL
Mask=0
If (Num And &H40000000)<>0 Then Mask=&H80000000
Num=(Num And &H3FFFFFFF)*2 Or Mask
Next
SHL = Num
End Function
'Âß¼ÓÒÒÆ;
'ͬjavascriptÖеÄ>>>;
Private Function SHR(ByVal Num, ByVal iCL)
If Num>=2^31 Or Num<-(2^31) Then
Err.Raise 6 : Exit Function
End If
Dim i, Mask, iCN
If Abs(iCL) >= 32 Then iCL = iCL - Fix(iCL/32)*32
If iCL<0 Then iCL = iCL + 32
If Num<0 Then Num = Num + 2^31 : iCN = 2^(31-iCL)
For i=1 To iCL
Mask=0
If (Num And &H80000000)<>0 Then Mask=&H40000000
Num=(Num And &H7FFFFFFF)\2 Or Mask
Next
SHR = Num + iCN
End Function
'ËãÊõÓÒÒÆ;
'ͬjavascriptÖеÄ>>;
Private Function SAR(ByVal Num, ByVal iCL)
If Num>=2^31 Or Num<-(2^31) Then
Err.Raise 6 : Exit Function
End If
If Abs(iCL) >= 32 Then iCL = iCL - Fix(iCL/32)*32
If iCL<0 Then iCL = iCL + 32
Dim i, Mask
For i=1 To iCL
Mask=0
If (Num And &H80000000)<>0 Then Mask=&HC0000000
Num=(Num And &H7FFFFFFF)\2 Or Mask
Next
SAR = Num
End Function
'¶þ½øÖÆ×Ö·û´®×ª»»Îªutf-8±àÂëµÄ×Ö·û´®;
'ps: bin±ØÐëÊÇÒÔutf-8±àÂëµÄ¶þ½øÖÆ×Ö·û´®;
Private Function bin2utf(ByVal bin)
Dim i, sLen, iAsc, iAsc2, iAsc3
sLen = LenB(bin)
For i=1 To sLen
iAsc = AscB(MidB(bin,i,1))
If iAsc>=0 And iAsc<=127 Then 'µ¥×Ö½Ú;
bin2utf = bin2utf & Chr(iAsc)
ElseIf iAsc >= 224 And iAsc <= 239 Then 'Èý×Ö½Ú;
iAsc2 = AscB(MidB(bin,i+1,1))
iAsc3 = AscB(MidB(bin,i+2,1))
bin2utf = bin2utf & ChrW(CDbl(iAsc-224) * 4096 + CDbl((iAsc2-128) * 64) + CDbl(iAsc3-128))
i=i+2
ElseIf iAsc >= 192 And iAsc <= 223 Then 'Ë«×Ö½Ú;
iAsc2 = AscB(MidB(bin,i+1,1))
bin2utf = bin2utf & ChrW(CDbl(iAsc-192) * (2^6) + CDbl(iAsc2-128))
i=i+1
End If
Next
End Function
'¶þ½øÖÆ×Ö·û´®×ª»»Îªgb2312±àÂëµÄ×Ö·û´®;
'ps: bin±ØÐëÊÇÒÔgb2312±àÂëµÄ¶þ½øÖÆ×Ö·û´®;
Private Function bin2uni(ByVal bin)
Dim i, sLen, iAsc
sLen = LenB(bin)
For i=1 To sLen
iAsc = AscB(MidB(bin,i,1))
If iAsc>=0 And iAsc<=127 Then
bin2uni = bin2uni & Chr(iAsc)
Else
i=i+1
If i <= sLen Then
bin2uni = bin2uni & Chr(AscW(MidB(bin,i,1) & MidB(bin,i-1,1)))
ElseIf i=sLen+1 Then
bin2uni = bin2uni & Chr(AscB(MidB(bin,i-1,1)))
End If
End If
Next
End Function
'×Ö·û´®×ª»»Îª¶þ½øÖÆ×Ö½Ú×Ö·û´®;
'ps:¿í×Ö·û³¤¶È¸ù¾ÝÎĵµ±àÂ벻ͬ¶ø²»Í¬;
'eg:gb2312-ÖÐÎÄÕ¼2×Ö½Ú;utf-8ÖÐÎÄÕ¼3×Ö½Ú;
Private Function str2bin(ByVal str)
Dim i, j, istr, iarr
For i=1 To Len(str)
istr = mid(str,i,1)
istr = Replace(Server.UrlEncode(istr),"+"," ")
If len(istr) = 1 Then
str2bin = str2bin & chrB(AscB(istr))
Else
iarr = split(istr,"%")
For j=1 To ubound(iarr)
str2bin = str2bin & chrB("&H" & iarr(j))
Next
End If
Next
End Function
'16½øÖÆ×Ö·û´®×ª»»Îª¶þ½øÖÆ×Ö·û´®;
Private Function hex2bin(ByVal str)
Dim i
For i = 1 To Len(str) Step 2
hex2bin = hex2bin & ChrB("&H" & Mid(str, i, 2))
Next
End Function
'¶þ½øÖÆ×Ö·û´®×ª»»Îª16½øÖÆ×Ö·û´®;
Private Function bin2hex(ByVal str)
Dim t, i
For i = 1 To LenB(str)
t = Hex(AscB(MidB(str, i, 1)))
If (Len(t) < 2) Then
while (Len(t) < 2)
t = "0" & t
Wend
End If
bin2hex = LCase(bin2hex & t)
Next
End Function
End Class
%>