求ASP版的BASE62加密解密代码

lovemmc 2012-03-03 02:18:42
网上能找到PHP的,但找不到ASP版的,求个用,谢谢了~~~~
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookee 2012-03-03
  • 打赏
  • 举报
回复
1. base64是编码而不是加密算法。用于把非Ascii字符转成7位ascii字符来传递,自然是比原字符串长。
2. = / +是base64算法规定的,当然可以用其他字符,不过要自己写算法了,如上面的mc_astrB64Alphabet。
3. 加密算法也不能保证密文比较短。用压缩算法或许可以,但对短字符串的效果不一定好。
lovemmc 2012-03-03
  • 打赏
  • 举报
回复
哦,对了,最好加密后没有 =,/,+ 这种字符,万分感谢~
lovemmc 2012-03-03
  • 打赏
  • 举报
回复
上面两个我试了一下,怎么有些字符好像加密后比BASE64的还要长呢?
我是用做网站搜索关键字URL传递参数加密用的,接收页面再解密出来。
有能加密成短点的吗?
hookee 2012-03-03
  • 打赏
  • 举报
回复
简单点:

<%
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))
%>
hookee 2012-03-03
  • 打赏
  • 举报
回复

<%

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))
%>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧