有没有和php中base64_encode和base64_decode一样效果的两个asp函数?

dw2003 2008-04-02 02:52:16
有没有和php中base64_encode和base64_decode一样效果的两个asp函数?
我在网上找到两个base64encode和base64decode是asp版的,但同样一字符串,用base64_encode和base64encode加密后的结果就是不同,因为我现在想实现用php中的base64_encode加密再用asp的base64decode解密,大家有这样的两个函数吗?
...全文
359 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cndrip 2009-05-31
  • 打赏
  • 举报
回复
不错,我找了一个星期 总算在这里找到了
ab520ah 2008-04-03
  • 打赏
  • 举报
回复
顶楼主你一下。
http://qzshi.com
网站建设技术论坛
另外招版主,或合作管理员,有兴趣的加群4228406
hookee 2008-04-02
  • 打赏
  • 举报
回复
初步比较了下,基本额上是和php的一样,试试看
用法 Encode(string)


CONST BASE_64_MAP="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim MapEnc(63)
Dim MapDec(127)
Dim i
For i=0 To 63
MapEnc(i)=Mid(BASE_64_MAP,i+1,1)
Next
For i=0 To 63
MapDec(Asc(MapEnc(i)))=i
Next
Set i=Nothing
Private Function DecToBin(intDecimal)
Dim strBinary,blnFlag
strBinary=""
blnFlag=True
Do While blnFlag
strBinary=Cstr(intDecimal AND &H01)&strBinary
intDecimal=intDecimal\2
If intDecimal=0 Then blnFlag=False
Loop
Set blnFlag=Nothing
strBinary=Right("00000000"&strBinary,8)
DecToBin=strBinary
Set strBinary=Nothing
End Function
Private Function BinToDec(strBin)
Dim intDec,i,j
intDec=0
j=Len(strBin)
For i=1 To j
intDec=intDec+2^(j-i)*CInt(Mid(strBin,i,1))
Next
Set i=Nothing
Set j=Nothing
BinToDec=intDec
Set intDec=Nothing
End Function
Private Function Bin24Encode(strBin24)
Dim strEncoder,strBin6
strEncoder=""
If (Len(strBin24)<=8) Then
strBin24=Left(strBin24&"00000000",8)
strBin6="00"&Mid(strBin24,1,6)
strEncoder=MapEnc(BinToDec(strBin6))
strBin6="00"&Mid(strBin24,7,2)&"0000"
strEncoder=strEncoder&MapEnc(BinToDec(strBin6))
strEncoder=strEncoder&"=="
Else If (Len(strBin24)<=16) Then
strBin24=Left(strBin24&"00000000",16)
strBin6="00"&Mid(strBin24,1,6)
strEncoder=MapEnc(BinToDec(strBin6))
strBin6="00"&Mid(strBin24,7,6)
strEncoder=strEncoder&MapEnc(BinToDec(strBin6))
strBin6="00"&Mid(strBin24,13,4)&"00"
strEncoder=strEncoder&MapEnc(BinToDec(strBin6))
strEncoder=strEncoder&"="
Else
strBin24=Left(strBin24&"00000000",24)
strBin6="00"&Mid(strBin24,1,6)
strEncoder=MapEnc(BinToDec(strBin6))
strBin6="00"&Mid(strBin24,7,6)
strEncoder=strEncoder&MapEnc(BinToDec(strBin6))
strBin6="00"&Mid(strBin24,13,6)
strEncoder=strEncoder&MapEnc(BinToDec(strBin6))
strBin6="00"&Mid(strBin24,19,6)
strEncoder=strEncoder&MapEnc(BinToDec(strBin6))
End If
End If
Set strBin6=Nothing
Bin24Encode=strEncoder
Set strEncoder=Nothing
End Function
Private Function HexToDec(strHex)
Dim intDec,i,j
j=Len(strHex)
intDec=0
For i=1 To j
Select Case Mid(strHex,i,1)
Case "0" intDec=intDex+16^(j-i)*0
Case "1" intDec=intDex+16^(j-i)*1
Case "2" intDec=intDex+16^(j-i)*2
Case "3" intDec=intDex+16^(j-i)*3
Case "4" intDec=intDex+16^(j-i)*4
Case "5" intDec=intDex+16^(j-i)*5
Case "6" intDec=intDex+16^(j-i)*6
Case "7" intDec=intDex+16^(j-i)*7
Case "8" intDec=intDex+16^(j-i)*8
Case "9" intDec=intDex+16^(j-i)*9
Case "A" intDec=intDex+16^(j-i)*10
Case "B" intDec=intDex+16^(j-i)*11
Case "C" intDec=intDex+16^(j-i)*12
Case "D" intDec=intDex+16^(j-i)*13
Case "E" intDec=intDex+16^(j-i)*14
Case "F" intDec=intDex+16^(j-i)*15
End Select
Next
Set i=Nothing
HexToDec=intDec
Set intDec=Nothing
End Function
Private Function HexToBin(strHex)
Dim strBin,i,j
j=Len(strHex)
strBin=""
For i=1 To j
Select Case Mid(strHex,i,1)
Case "0" strBin=strBin&"0000"
Case "1" strBin=strBin&"0001"
Case "2" strBin=strBin&"0010"
Case "3" strBin=strBin&"0011"
Case "4" strBin=strBin&"0100"
Case "5" strBin=strBin&"0101"
Case "6" strBin=strBin&"0110"
Case "7" strBin=strBin&"0111"
Case "8" strBin=strBin&"1000"
Case "9" strBin=strBin&"1001"
Case "A" strBin=strBin&"1010"
Case "B" strBin=strBin&"1011"
Case "C" strBin=strBin&"1100"
Case "D" strBin=strBin&"1101"
Case "E" strBin=strBin&"1110"
Case "F" strBin=strBin&"1111"
End Select
Next
Set i=Nothing
Set j=Nothing
HexToBin=strBin
Set strBin=Nothing
End Function
Private Function BinToHex(strBin)
Dim strHex,strBin4
strHex=""
Do While strBin<>""
strBin4=Mid(strBin,1,4)
If Len(strBin)>4 Then
strBin=Mid(strBin,5,Len(strBin)-4)
Else
strBin=""
End If
Select Case strBin4
Case "0000" strHex=strHex&"0"
Case "0001" strHex=strHex&"1"
Case "0010" strHex=strHex&"2"
Case "0011" strHex=strHex&"3"
Case "0100" strHex=strHex&"4"
Case "0101" strHex=strHex&"5"
Case "0110" strHex=strHex&"6"
Case "0111" strHex=strHex&"7"
Case "1000" strHex=strHex&"8"
Case "1001" strHex=strHex&"9"
Case "1010" strHex=strHex&"A"
Case "1011" strHex=strHex&"B"
Case "1100" strHex=strHex&"C"
Case "1101" strHex=strHex&"D"
Case "1110" strHex=strHex&"E"
Case "1111" strHex=strHex&"F"
End Select
Loop
Set strBin4=Nothing
BinToHex=strHex
Set strHex=Nothing
End Function
PUBLIC Function Encode(strText)
Dim strTemp24,strBinarySource,strCode,intAsc,strHex,i,j
strTemp24=""
strBinarySource=""
strCode=""
j=Clng(Len(strText))
For i=1 To j
intAsc=Asc(Mid(strText,i,1))
If intAsc>=0 AND intAsc<128 Then
strBinarySource=strBinarySource&DecToBin(intAsc)
Else
strHex=CStr(Hex(intAsc))
strHex=Right("0000"&strHex,4)
strBinarySource=strBinarySource & HexToBin(strHex)
End If
Next
Do While (strBinarySource<>"")
If Clng(Len(strBinarySource))>=24 Then
strTemp24=Mid(strBinarySource,1,24)
strBinarySource=Mid(strBinarySource,25,Len(strBinarySource)-24)
Else
strTemp24=Mid(strBinarySource,1,Len(strBinarySource))
strBinarySource=""
End If
strCode=strCode&Bin24Encode(strTemp24)
Loop
Set i=Nothing
Set j=Nothing
Set intAsc=Nothing
Set strTemp24=Nothing
Set strBinarySource=Nothing
Set i=Nothing
Encode=strCode
Set strCode=Nothing
End Function
PUBLIC Function Decode(strCode)
Dim i,j,strText,strBinarySource,strTemp8,intIndex
j=Clng(Len(strCode))
strText=""
strBinarySource=""
For i=1 To j
intIndex=MapDec(Asc(Mid(strCode,i,1)))
If Mid(strCode,i,1)<>"=" Then strBinarySource=strBinarySource&Right(DecToBin(intIndex),6)
Next
Do While (strBinarySource<>"")
If Len(strBinarySource)>8 Then
strTemp8=Mid(strBinarySource,1,8)
strBinarySource=Mid(strBinarySource,9,Len(strBinarySource)-8)
Else
If Len(strBinarySource)=8 Then strTemp8=Mid(strBinarySource,1,8)
strBinarySource=""
End If
If Mid(strTemp8,1,1)="0" Then
strText=strText&Chr(BinToDec(strTemp8))
Else
If Len(strBinarySource)>8 Then
strTemp8=strTemp8&Mid(strBinarySource,1,8)
strBinarySource=Mid(strBinarySource,9,Len(strBinarySource)-8)
strText=strText& Chr("&H"& BinToHex(strTemp8))
Else
If Len(strBinarySource)=8 Then
strTemp8=strTemp8&Mid(strBinarySource,1,8)
'response.write BinToHex(strTemp8)&"<br>"
strText=strText& Chr("&H" & BinToHex(strTemp8))
End If
strBinarySource=""
End If
End If
Loop
Set strBinarySource=Nothing
Set intIndex=Nothing
Set i=Nothing
Set j=Nothing
Decode=strText
Set strText=Nothing
End Function
No_Data_Found 2008-04-02
  • 打赏
  • 举报
回复
代码来源

http://hi.baidu.com/viewhainan/blog/item/3d52d21300b770025aaf5305.html
No_Data_Found 2008-04-02
  • 打赏
  • 举报
回复
估计 在这版混的大都不懂php

  OPTION EXPLICIT 
  const BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  dim newline
  dim Base64EncMap(63)
  dim Base64DecMap(127)
  dim inp,hu,encode
  call initCodecs '初始化
  inp = "<WORD处理后的asp代码>" '将要保护的asp代码用WORD处理,然后填在此处
  hu= base64Encode(inp) '调用函数base64Encode进行加密,得到密文hu
  Response.Write(hu) '显示密文
  PUBLIC SUB initCodecs() '初始化函数initCodecs
  newline = "<P>" & chr(13) & chr(10)
  dim max, idx
  max = len(BASE_64_MAP_INIT)
  for idx = 0 to max - 1
  Base64EncMap(idx) = mid(BASE_64_MAP_INIT, idx + 1, 1)
  next
  for idx = 0 to max - 1
  Base64DecMap(ASC(Base64EncMap(idx))) = idx
  next
  END SUB
  PUBLIC FUNCTION base64Encode(plain) '加密函数base64Encode
  if len(plain) = 0 then
  base64Encode = ""
  exit function
  end if
  dim ret, ndx, by3, first, second, third
  by3 = (len(plain) \ 3) * 3
  ndx = 1
  do while ndx <= by3
  first = asc(mid(plain, ndx+0, 1))
  second = asc(mid(plain, ndx+1, 1))
  third = asc(mid(plain, ndx+2, 1))
  ret = ret & Base64EncMap( (first \ 4) AND 63 )
  ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second \ 16) AND 15 ) )
  ret = ret & Base64EncMap( ((second * 4) AND 60) + ((third \ 64) AND 3 ) )
  ret = ret & Base64EncMap( third AND 63)
  ndx = ndx + 3
  loop
  if by3 < len(plain) then
  first = asc(mid(plain, ndx+0, 1))
  ret = ret & Base64EncMap( (first \ 4) AND 63 )
  if (len(plain) MOD 3 ) = 2 then
  second = asc(mid(plain, ndx+1, 1))
  ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second \ 16) AND 15 ) )
  ret = ret & Base64EncMap( ((second * 4) AND 60) )
  else
  ret = ret & Base64EncMap( (first * 16) AND 48)
  ret = ret '& "="
  end if
  ret = ret '& "="
  end if
  base64Encode = ret
  END FUNCTION



Dim Hu,Hu2 
  '拷贝“欲保护asp代码”的密文 将之存放到Hu变量中
  Hu=""
  Hu2= base64Decode(hu) '还原要保护的ASP代码
  execute(UnEncode(Hu2)) '还原单引号、回车换行,并执行原代码
  '解密函数base64Decode
  FUNCTION base64Decode(scrambled)
  if len(scrambled) = 0 then
  base64Decode = ""
  exit function
  end if
  dim realLen
  realLen = len(scrambled)
  do while mid(scrambled, realLen, 1) = "="
  realLen = realLen - 1
  loop
  dim ret, ndx, by4, first, second, third, fourth
  ret = ""
  by4 = (realLen \ 4) * 4
  ndx = 1
  do while ndx <= by4
  first = Base64DecMap(asc(mid(scrambled, ndx+0, 1)))
  second = Base64DecMap(asc(mid(scrambled, ndx+1, 1)))
  third = Base64DecMap(asc(mid(scrambled, ndx+2, 1)))
  fourth = Base64DecMap(asc(mid(scrambled, ndx+3, 1)))
  ret = ret & chr( ((first * 4) AND 255) + ((second \ 16) AND 3))
  ret = ret & chr( ((second * 16) AND 255) + ((third \ 4) AND 15))
  ret = ret & chr( ((third * 64) AND 255) + (fourth AND 63))
  ndx = ndx + 4
  loop
  if ndx < realLen then
  first = Base64DecMap(asc(mid(scrambled, ndx+0, 1)))
  second = Base64DecMap(asc(mid(scrambled, ndx+1, 1)))
  ret = ret & chr( ((first * 4) AND 255) + ((second \ 16) AND 3))
  if realLen MOD 4 = 3 then
  third = Base64DecMap(asc(mid(scrambled,ndx+2,1)))
  ret = ret & chr( ((second * 16) AND 255) + ((third \ 4) AND 15))
  end if
  end if
  base64Decode = ret
  END FUNCTION
  '还原单引号、回车换行函数UnEncode
  function UnEncode(cc)
  for i = 1 to len(cc)
  if mid(cc,i,1)<> "水" then
  if mid(cc,i,1)="加" then
  temp = """" & temp
  else
  temp = Mid(cc, i, 1) + temp
  end if
  else
  temp=newline&temp
  end if
  next
  UnEncode=temp
  end function

CNBJX-原创函数,首发CSND 3.1 Base64 ------------------------------------------------------------------------------- Base64Decode(Str) Base64DecodeRaw(Str) as byte() Base64Encode(Str) FileBase64(file) 3.2 Hex ------------------------------------------------------------------------------- HexDecode(Str) HexDecodeRaw(Str) as byte() HexEncode(Str) File2Hex(file) 3.3 hash String ------------------------------------------------------------------------------- stringOrByte : 可以是字条串或字节数组 ChatSet : 可选,指定编码 MD2(stringOrByte, [ChatSet As String]) As String MD4(stringOrByte, [ChatSet As String]) As String MD5(stringOrByte, [ChatSet As String]) As String SHA1(stringOrByte, [ChatSet As String]) SHA256(stringOrByte, [ChatSet As String]) As String SHA384(stringOrByte, [ChatSet As String]) As String SHA512(stringOrByte, [ChatSet As String]) As String 3.4 hash Byte ------------------------------------------------------------------------------- abytData : 字节数组 asp里请加()号 如: bytes="" md5_byte((bytes),0,0) 可选参数 iStart iEnd 默认为0,取整个 bytes的hash值 ---------------------------------------------------- [可选] iStart: 起始位置 [可选] iEnd:结束位置 分块取值有几种情况 1: iStart = 0 , iEnd = 1024 * 1024 * 1 '读取前面1M 2: iStart = -1024 * 1024 * 1 , iEnd = 0 '读取后面1M 3: iStart = 10, iEnd = iStart + 10 '读取第10个字节后的10个字节 (10-20) 4: iStart = -20,iEnd = -10 '读取尾部 (-20 -> -10 的字节) ---------------------------------------------------- MD2_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String MD4_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String MD5_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA1_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA256_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA384_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA

28,391

社区成员

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

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