ASP BASE64加解密(亲测可用)
程序员文章站
2022-07-02 18:19:11
核心代码:
<%
' option explicit
const base_64_map_init = "abcdefghijklmnopqr...
核心代码:
<% ' option explicit const base_64_map_init = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/" dim newline dim base64encmap(63) dim base64decmap(127) '初始化函数 public sub 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 'base64加密函数 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 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 'base64解密函数 public 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 %>
使用方法:
' 初始化 call initcodecs response.write(base64encode("之我要加密的字符串")) response.write(base64decode("bwfycziwmtawmjiw0"))
上一篇: iPhone开启iCloud钥匙串之后会储存哪些信息
下一篇: asp实现截取字符串函数
推荐阅读
-
U盘内容被病毒隐藏的解决办法(亲测可用)
-
详解Vue项目引入CreateJS的方法(亲测可用)
-
微信小程序使用websocket通讯的demo,含前后端代码,亲测可用
-
asp.net DataGridView导出到Excel的三个方法[亲测]
-
phpstorm最新激活码分享亲测phpstorm2020.2.3版可用
-
VMWare中CentOS ifcfg-eth0配置方法(亲测直接可用)
-
asp base64加解密函数代码
-
详解Vue项目引入CreateJS的方法(亲测可用)
-
关闭不了Linux防火墙,试一下这五条命令,亲测可用-
-
亲测可用!微信小程序实现下载预览文件,导出及保存文件及excel