当前位置: 首页 > 图文教程 > 网络编程 > ASP > 如何用asp进行base64加密

ASP
介绍一下GETROWS的用法
一个在vbscript中读取cookie的程序函数
用err.raise自定义错误信息
一段返回随机记录的代码
基于ACCESS数据库的纯asp论坛制作心得
不用Golobal.asa和session实现在线人数统计
在ASP里建表
结束ADOVB.INC的办法
存储过程分页
友情连接浏览器
怎样使用ASP实现Ping
用ASP读取Windows标准INI格式文件
使用ActiveX控件开发网页常见的问题
两个获取http页面的c#函数
将html源代码规范化,转换成XSL代码的asp工具
已调试好的asp程序在VB中转换为组件的技巧
关于如何动态地在同一页面实现两个互传
关于图片与文本同存在数据库中的具体思路
实现分页的例子-使用存储过程来实现分页
使用索引服务器- 使用索引服务器的对象

ASP 中的 如何用asp进行base64加密


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 26 ::
收藏到网摘: n/a

  <%
     OPTION EXPLICIT
     const BASE_64_MAP_INIT =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
     dim nl
     ' zero based arrays
     dim Base64EncMap(63)
     dim Base64DecMap(127)

     ' must be called before using anything else
     PUBLIC SUB initCodecs()
          ' init vars
          nl = "<P>" & chr(13) & chr(10)
          ' setup base 64
          dim max, idx
             max = len(BASE_64_MAP_INIT)
          for idx = 0 to max - 1
               ' one based string
               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

     ' encode base 64 encoded string
     PUBLIC FUNCTION base64Encode(plain)

          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
          ' check for stragglers
          if by3 < len(plain) then
            &