28,391
社区成员
发帖
与我相关
我的任务
分享
<%
Function B64Encode(s)
Dim oDoc, oStream1, oStream2
Set oStream1 = CreateObject("ADODB.Stream")
With oStream1
.Type = 2
.Mode = 3
.Open
.WriteText s
.Position = 1
End With
Set oStream2 = CreateObject("ADODB.Stream")
With oStream2
.Type = 1
.Mode = 3
.Open
End With
oStream1.CopyTo oStream2
Set oStream1 = Nothing
oStream2.Position = 1
Set oDoc = CreateObject("Msxml2.DOMDocument")
With oDoc
.loadXml "<root/>"
.DocumentElement.DataType = "bin.base64"
.DocumentElement.NodeTypedValue = oStream2.Read(oStream2.size)
B64Encode = .DocumentElement.text
End With
Set oStream2 = Nothing
Set oDoc = Nothing
End Function
Function B64Decode(s)
Dim oDoc
Set oDoc = CreateObject("Msxml2.DOMDocument")
With oDoc
.loadXml "<root/>"
.DocumentElement.DataType = "bin.base64"
.DocumentElement.text = s
B64Decode = .DocumentElement.NodeTypedValue
End With
Set oDoc = Nothing
End Function
a="1中文"
Response.Write B64Decode(B64Encode(a))
%>
<%
mc_astrB64Alphabet = Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",_
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",_
"0","1","2","3","4","5","6","7","8","9","+","/")
Function B64Encode(byval strData)
dim i,j,a,b,e
dim A1,A2,A3,A4,B1,B2,B3,B4
dim lngSurffix
dim strRet
lngSurffix=(lenb(strData) mod 3)
for i=0 to lenb(strData)\3-1
A1=ascb(midb(strData,i*3+1,1))
A2=ascb(midb(strData,i*3+2,1))
A3=ascb(midb(strData,i*3+3,1))
B1= ((A1 and 252)\04)
B2=((A1 And 03)*16) or ((A2 and 240)\16)
B3=((A2 And 15)*04) Or ((A3 And 192)\64)
B4=((A3 and 63)*01)
strRet=strRet & mc_astrB64Alphabet(B1) & mc_astrB64Alphabet(B2) & mc_astrB64Alphabet(B3) & mc_astrB64Alphabet(B4)
next
if lngSurffix=1 then
A1=ascb(midb(strData,i*3+1,1))
B1=((A1 and 252)\04)
B2=((A1 and 03)*16)
strRet=strRet & mc_astrB64Alphabet(B1) & mc_astrB64Alphabet(B2) & "=="
elseif lngSurffix=2 Then
A1=ascb(midb(strData,i*3+1,1))
A2=ascb(midb(strData,i*3+2,1))
B1=((A1 and 252)\04)
B2=((A1 and 03)*16) or ((A2 and 240)\16)
B3=((A2 and 15)*04)
strRet=strRet & mc_astrB64Alphabet(B1) & mc_astrB64Alphabet(B2) & mc_astrB64Alphabet(B3) & ""=""
end if
B64Encode=strRet
end Function
Function B64Decode(s)
Dim oDoc
Set oDoc = CreateObject("Msxml2.DOMDocument")
With oDoc
.loadXml "<root/>"
.DocumentElement.DataType = "bin.base64"
.DocumentElement.text = s
B64Decode = .DocumentElement.NodeTypedValue
End With
Set oDoc = Nothing
End Function
a="中文1"
Response.Write B64Decode(B64Encode(a))
%>