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

ASP
使用索引服务器 - 创建ASP页面
使用索引服务器 - 增加属性
用TDC建立自己的数据库格式
较长text型数据无法在Asp页面中取出的解决办法
用ASP控制Flash
计算ASP页面的载入时间
页面延迟的两个简单方法
将ASP生成的内容写入响应流中最有效的方法
如何使用asp创建dsn?
清除浏览器历史记录代码
不离开页面刷新数据
得到表中字段属性代码
用js制作完善的日,月组合下拉框.
WEB页面实现淡入淡出菜单
不用组件来实现StrCat函数的功能
不用java的垂直滚动看板
使用Server.scripttimeout来减少ASP意外错误而使务器瘫痪
ODBC Drivers错误80004005的解决办法
用ASP方式实现动态伸缩形式列表主页
如何使ASP程序暂停指定的时间后再继续执行

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 22 ::
收藏到网摘: 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
            &