帖子长度限制,只好发个精简的!
<%
Class clsCookieX
Private ErrMsg,bHasErr
Private sBASE_64_CHARACTERS
Private Sub Class_Initialize()
ErrMsg="":bHasErr=False
sBASE_64_CHARACTERS = "aT@zpMme5DHWQ4ER37dvgPYxu9JcB1ULw6sKihCljIqnSyk2VfOr8GFX0A!tNZob"
sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS)
End Sub
Private Sub Class_Terminate()
End Sub
Private Sub AddErr(s)
ErrMsg=ErrMsg&"Cookie操作出错信息 - "&s&HTML_BR
bHasErr=True
End Sub
Public Function GetErr()
GetErr=ErrMsg
End Function
Public Sub ErrClear()
ErrMsg=""
bHasErr=False
End Sub
Public Property Get HasErr()
HasErr=bHasErr
End Property
Public Property Let Item(k,v)
Response.Cookies(encode(k))=encode(v)
End Property
Public Default Property Get Item(k)
Item=decode(Request.Cookies(encode(k)))
End Property
Public Function Remove(k)
k=encode(k)
Response.Cookies(k)=""
Response.Cookies(k).Expires=DateAdd("d",-1,Now)
End Function
Public Property Let Expires(k,v)
Response.Cookies(encode(k)).Expires=v
End Property
Public Function Exists(k)
k=encode(k)
If Len(Request.Cookies(k))=0 Then
Exists=False
Else
Exists=True
End If
End Function
Function encode(v)
encode=strAnsi2Unicode(Base64encode(strUnicode2Ansi(v)))
End Function
Function decode(v)
decode=strAnsi2Unicode(Base64decode(strUnicode2Ansi(v)))
End Function
Function strUnicodeLen(asContents)
Dim len1, k, i, Asc1, asContents1
asContents1 = "a" & asContents
len1 = Len(asContents1)
k = 0
For i = 1 To len1
Asc1 = Asc(Mid(asContents1, i, 1))
If Asc1 < 0 Then Asc1 = 65536 + Asc1
If Asc1 > 255 Then
k = k + 2
Else
k = k + 1
End If
Next
strUnicodeLen = k - 1
End Function
Function strUnicode2Ansi(asContents)
Dim len1, k, i, Asc1, varchar, varasc, varhex, varlow, varhigh
strUnicode2Ansi = ""
len1 = Len(asContents)
For i = 1 To len1
varchar = Mid(asContents, i, 1)
varasc = Asc(varchar)
If varasc < 0 Then varasc = varasc + 65536
If varasc > 255 Then
varhex = Hex(varasc)
varlow = Left(varhex, 2)
varhigh = Right(varhex, 2)
strUnicode2Ansi = strUnicode2Ansi & ChrB("&H" & varlow) & ChrB("&H" & varhigh)
Else
strUnicode2Ansi = strUnicode2Ansi & ChrB(varasc)
End If
Next
End Function
Function strAnsi2Unicode(asContents)
Dim len1, k, i, Asc1, varchar, varasc, varhex, varlow, varhigh
strAnsi2Unicode = ""
len1 = LenB(asContents)
If len1 = 0 Then Exit Function
For i = 1 To len1
varchar = MidB(asContents, i, 1)
varasc = AscB(varchar)
If varasc > 127 Then
strAnsi2Unicode = strAnsi2Unicode & Chr(AscW(MidB(asContents, i + 1, 1) & varchar))
i = i + 1
Else
strAnsi2Unicode = strAnsi2Unicode & Chr(varasc)
End If
Next
End Function
Function Base64encode(asContents)
Dim lnPosition
Dim lsResult
Dim Char1
Dim Char2
Dim Char3
Dim Char4
Dim Byte1
Dim Byte2
Dim Byte3
Dim SaveBits1
Dim SaveBits2
Dim lsGroupBinary
Dim lsGroup64
Dim M3, len1, len2
len1 = LenB(asContents)
If len1 < 1 Then
Base64encode = ""
Exit Function
End If
M3 = len1 Mod 3
If M3 > 0 Then asContents = asContents & String(3 - M3, ChrB(0))
If M3 > 0 Then
len1 = len1 + (3 - M3)
len2 = len1 - 3
Else
len2 = len1
End If
lsResult = ""
For lnPosition = 1 To len2 Step 3
lsGroup64 = ""
lsGroupBinary = MidB(asContents, lnPosition, 3)
Byte1 = AscB(MidB(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = AscB(MidB(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = AscB(MidB(lsGroupBinary, 3, 1))
Char1 = MidB(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = MidB(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = MidB(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
Char4 = MidB(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1)
lsGroup64 = Char1 & Char2 & Char3 & Char4
lsResult = lsResult & lsGroup64
Next
If M3 > 0 Then
lsGroup64 = ""
lsGroupBinary = MidB(asContents, len2 + 1, 3)
Byte1 = AscB(MidB(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = AscB(MidB(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = AscB(MidB(lsGroupBinary, 3, 1))
Char1 = MidB(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
Char2 = MidB(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = MidB(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
If M3 = 1 Then
lsGroup64 = Char1 & Char2 & ChrB(39) & ChrB(39)
Else
lsGroup64 = Char1 & Char2 & Char3 & ChrB(39)
End If
lsResult = lsResult & lsGroup64
End If
Base64encode = lsResult
End Function
Function Base64decode(asContents)
Dim lsResult
Dim lnPosition
Dim lsGroup64, lsGroupBinary
Dim Char1, Char2, Char3, Char4
Dim Byte1, Byte2, Byte3
Dim M4, len1, len2
len1 = LenB(asContents)
M4 = len1 Mod 4
If len1 < 1 Or M4 > 0 Then
Base64decode = ""
Exit Function
End If
If MidB(asContents, len1, 1) = ChrB(39) Then M4 = 3
If MidB(asContents, len1 - 1, 1) = ChrB(39) Then M4 = 2
If M4 = 0 Then
len2 = len1
Else
len2 = len1 - 4
End If
For lnPosition = 1 To len2 Step 4
lsGroupBinary = ""
lsGroup64 = MidB(asContents, lnPosition, 4)
Char1 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 1, 1)) - 1
Char2 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 2, 1)) - 1
Char3 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 3, 1)) - 1
Char4 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 4, 1)) - 1
Byte1 = ChrB(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & ChrB(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = ChrB((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
lsGroupBinary = Byte1 & Byte2 & Byte3
lsResult = lsResult & lsGroupBinary
Next
If M4 > 0 Then
lsGroupBinary = ""
lsGroup64 = MidB(asContents, len2 + 1, M4) & ChrB(65)
If M4 = 2 Then
lsGroup64 = lsGroup64 & ChrB(65)
End If
Char1 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 1, 1)) - 1
Char2 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 2, 1)) - 1
Char3 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 3, 1)) - 1
Char4 = InStrB(sBASE_64_CHARACTERS, MidB(lsGroup64, 4, 1)) - 1
Byte1 = ChrB(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & ChrB(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF)
Byte3 = ChrB((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
If M4 = 2 Then
lsGroupBinary = Byte1
ElseIf M4 = 3 Then
lsGroupBinary = Byte1 & Byte2
End If
lsResult = lsResult & lsGroupBinary
End If
Base64decode = lsResult
End Function
End Class
Dim startime
startime=Timer
Response.Write "<pre>"
Dim c
Set c=New clsCookieX
c("hellow")="简体中文abc123我在!"
c("hellow1")="简体中文abc123我"
c("一二三四")="壹仟贰佰叁拾肆"
For i=1 To 10
Response.Write c("t"&i)
Next
Response.Write c("hellow")
Response.Write c("hellow1")
Response.Write "<hr>"
Response.Write Server.HTMLEncode(Request.ServerVariables("ALL_RAW"))
c.Remove("hellow")
c.Remove("hellow1")
Response.Write c.Exists("hellow1")
Response.Write FormatNumber((Timer-startime)*1000,3)
Response.Write "</pre>"
%>
Public Function Crypt(pLngMessage, pLngKey)
On Error Resume Next
Dim lLngMod
Dim lLngResult
Dim lLngIndex
If pLngKey Mod 2 = 0 Then
lLngResult = 1
For lLngIndex = 1 To pLngKey / 2
lLngMod = (pLngMessage ^ 2) Mod Modulus
' Mod may error on key generation
lLngResult = (lLngMod * lLngResult) Mod Modulus
If Err Then Exit Function
Next
Else
lLngResult = pLngMessage
For lLngIndex = 1 To pLngKey / 2
lLngMod = (pLngMessage ^ 2) Mod Modulus
On Error Resume Next
' Mod may error on key generation
lLngResult = (lLngMod * lLngResult) Mod Modulus
If Err Then Exit Function
Next
End If
Crypt = lLngResult
End Function
Public Function Encode(ByVal pStrMessage)
Dim lLngIndex
Dim lLngMaxIndex
Dim lBytAscii
Dim lLngEncrypted
lLngMaxIndex = Len(pStrMessage)
If lLngMaxIndex = 0 Then Exit Function
For lLngIndex = 1 To lLngMaxIndex
lBytAscii = Asc(Mid(pStrMessage, lLngIndex, 1))
lLngEncrypted = Crypt(lBytAscii, PublicKey)
Encode = Encode & NumberToHex(lLngEncrypted, 4)
Next
End Function
Public Function Decode(ByVal pStrMessage)
Dim lBytAscii
Dim lLngIndex
Dim lLngMaxIndex
Dim lLngEncryptedData
Decode = ""
lLngMaxIndex = Len(pStrMessage)
For lLngIndex = 1 To lLngMaxIndex Step 4
lLngEncryptedData = HexToNumber(Mid(pStrMessage, lLngIndex, 4))
lBytAscii = Crypt(lLngEncryptedData, PrivateKey)
Decode = Decode & Chr(lBytAscii)
Next
End Function
Private Function NumberToHex(ByRef pLngNumber, ByRef pLngLength)
NumberToHex = Right(String(pLngLength, "0") & Hex(pLngNumber), pLngLength)
End Function
Private Function HexToNumber(ByRef pStrHex)
HexToNumber = CLng("&h" & pStrHex)
End Function
End Class
%>
test.asp
<!--#INCLUDE FILE="RSA.asp"-->
<%
function Encryptstr(Message)
Dim LngKeyE
Dim LngKeyD
Dim LngKeyN
Dim StrMessage
Dim ObjRSA