ASP Base64位 加密解密
网上找了很多,运行时都会提示某个错误,有点乱。后面找到测试,这个转ASNI码的能实现
sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS) Function strUnicodeLen(asContents)
'计算unicode字符串的Ansi编码的长度
asContents1="a"&asContents
len1=len(asContents1)
k=
for i= to len1
asc1=asc(mid(asContents1,i,))
if asc1< then asc1=+asc1
if asc1> then
k=k+
else
k=k+
end if
next
strUnicodeLen=k-
End Function Function strUnicode2Ansi(asContents)
'将Unicode编码的字符串,转换成Ansi编码的字符串
strUnicode2Ansi=""
len1=len(asContents)
for i= to len1
varchar=mid(asContents,i,)
varasc=asc(varchar)
if varasc< then varasc=varasc+
if varasc> then
varHex=Hex(varasc)
varlow=left(varHex,)
varhigh=right(varHex,)
strUnicode2Ansi=strUnicode2Ansi & chrb("&H" & varlow ) & chrb("&H" & varhigh )
else
strUnicode2Ansi=strUnicode2Ansi & chrb(varasc)
end if
next
End function Function strAnsi2Unicode(asContents)
'将Ansi编码的字符串,转换成Unicode编码的字符串
strAnsi2Unicode = ""
len1=lenb(asContents)
if len1= then exit function
for i= to len1
varchar=midb(asContents,i,)
varasc=ascb(varchar)
if varasc > then
strAnsi2Unicode = strAnsi2Unicode & chr(ascw(midb(asContents,i+,) & varchar))
i=i+
else
strAnsi2Unicode = strAnsi2Unicode & chr(varasc)
end if
next
End function Function Base64encode(asContents)
'将Ansi编码的字符串进行Base64编码
'asContents应当是ANSI编码的字符串(二进制的字符串也可以)
Dim lnPosition
Dim lsResult
Dim Char1
Dim Char2
Dim Char3
Dim Char4
Dim Byte1
Dim Byte2
Dim Byte3
Dim SaveBits1
Dim SaveBits2
Dim lsGroupBinary
Dim lsGroup64
Dim m4,len1,len2 len1=Lenb(asContents)
if len1< then
Base64encode=""
exit Function
end if m3=Len1 Mod
If M3 > Then asContents = asContents & String(-M3, chrb())
'补足位数是为了便于计算 IF m3 > THEN
len1=len1+(-m3)
len2=len1-
else
len2=len1
end if lsResult = "" For lnPosition = To len2 Step
lsGroup64 = ""
lsGroupBinary = Midb(asContents, lnPosition, ) Byte1 = Ascb(Midb(lsGroupBinary, , )): SaveBits1 = Byte1 And
Byte2 = Ascb(Midb(lsGroupBinary, , )): SaveBits2 = Byte2 And
Byte3 = Ascb(Midb(lsGroupBinary, , )) Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And ) / ) + , )
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And ) / ) Or (SaveBits1 * ) And &HFF) + , )
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And ) / ) Or (SaveBits2 * ) And &HFF) + , )
Char4 = Midb(sBASE_64_CHARACTERS, (Byte3 And ) + , )
lsGroup64 = Char1 & Char2 & Char3 & Char4 lsResult = lsResult & lsGroup64
Next '处理最后剩余的几个字符
if M3 > then
lsGroup64 = ""
lsGroupBinary = Midb(asContents, len2+, ) Byte1 = Ascb(Midb(lsGroupBinary, , )): SaveBits1 = Byte1 And
Byte2 = Ascb(Midb(lsGroupBinary, , )): SaveBits2 = Byte2 And
Byte3 = Ascb(Midb(lsGroupBinary, , )) Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And ) / ) + , )
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And ) / ) Or (SaveBits1 * ) And &HFF) + , )
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And ) / ) Or (SaveBits2 * ) And &HFF) + , ) if M3= then
lsGroup64 = Char1 & Char2 & ChrB() & ChrB() '用=号补足位数
else
lsGroup64 = Char1 & Char2 & Char3 & ChrB() '用=号补足位数
end if
lsResult = lsResult & lsGroup64
end if
Base64encode = lsResult
End Function Function Base64decode(asContents)
'将Base64编码字符串转换成Ansi编码的字符串
'asContents应当也是ANSI编码的字符串(二进制的字符串也可以)
Dim lsResult
Dim lnPosition
Dim lsGroup64, lsGroupBinary
Dim Char1, Char2, Char3, Char4
Dim Byte1, Byte2, Byte3
Dim M4,len1,len2 len1= Lenb(asContents)
M4 = len1 Mod if len1 < or M4 > then
'字符串长度应当是4的倍数
Base64decode = ""
exit Function
end if '判断最后一位是不是 = 号
'判断倒数第二位是不是 = 号
'这里m4表示最后剩余的需要单独处理的字符个数
if midb(asContents, len1, ) = chrb() then m4=
if midb(asContents, len1-, ) = chrb() then m4= if m4 = then
len2=len1
else
len2=len1-
end if For lnPosition = To Len2 Step
lsGroupBinary = ""
lsGroup64 = Midb(asContents, lnPosition, )
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Byte1 = Chrb(((Char2 And ) / ) Or (Char1 * ) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And ) / ) Or (Char2 * ) And &HFF)
Byte3 = Chrb((((Char3 And ) * ) And &HFF) Or (Char4 And ))
lsGroupBinary = Byte1 & Byte2 & Byte3 lsResult = lsResult & lsGroupBinary
Next '处理最后剩余的几个字符
if M4 > then
lsGroupBinary = ""
lsGroup64 = Midb(asContents, len2+, m4) & chrB() 'chr(65)=A,转换成值为0
if M4= then '补足4位,是为了便于计算
lsGroup64 = lsGroup64 & chrB()
end if
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, , )) -
Byte1 = Chrb(((Char2 And ) / ) Or (Char1 * ) And &HFF)
Byte2 = lsGroupBinary & Chrb(((Char3 And ) / ) Or (Char2 * ) And &HFF)
Byte3 = Chrb((((Char3 And ) * ) And &HFF) Or (Char4 And )) if M4= then
lsGroupBinary = Byte1
elseif M4= then
lsGroupBinary = Byte1 & Byte2
end if lsResult = lsResult & lsGroupBinary
end if Base64decode = lsResult End Function
调用如下:
'加密
strAnsi2Unicode(Base64encode(strUnicode2Ansi("加密字符串")))
'解密
strAnsi2Unicode(Base64decode(strUnicode2Ansi("解密字符串")))
ASP Base64位 加密解密的更多相关文章
- base64位加密解密
1.base64位加密base64是用于传输8Bit字节代码,由上图的编码表可以知道,编码后的内容只包含这64个字符类型,所以称为base64编码 2.编码过程 : 首先将待编码的内容转换成8位二进制 ...
- 【支付专区】之对字符串数据进行Base64位加密,解密
加密,解密 String pwd="测试"; byte[] bytes = pwd.getBytes("UTF-8"); //加密 String pwdNew= ...
- ASP.NET常用加密解密方法
ASP.NET常用加密解密方法 一.MD5加密解密 1.加密 C# 代码 public static string ToMd5(string clearString) ...
- Java Base64位加密和解密(包括其他加密参考)
链接https://blog.csdn.net/longguangfu8/article/details/78948213 常用加密解密算法[RSA.AES.DES.MD5]介绍和使用 https:/ ...
- 【转】asp.net(c#)加密解密算法之sha1、md5、des、aes实现源码详解
原文地址:http://docode.top/Article/Detail/10003 目录: 1..Net(C#)平台下Des加密解密源代码 2..Net(C#)平台下Aes加密解密源代码 3..N ...
- Javascript实现base64的加密解密
//1.加密解密方法使用: //1.加密 var str = '124中文内容'; var base = new Base64(); var result = base.encode(str); // ...
- Javascript实现base64的加密解密【转】
场景 这几天使用PHP向前端传值的时候,遇到一个问题,要将代码传过去赋值.如果使用urlencode()和urldecode()函数,就会出现js无法解码的情况,因为php和js的相关函数算法不一致. ...
- php AES cbc模式 pkcs7 128位加密解密(微信小程序)
PHP AES CBC模式PKCS7 128位加密 加密: $key = '1234567812345678'; $iv = '1234567890123456'; $message = '12345 ...
- hash模块 hashlib不可逆加密 和 base64算法加密解密
hashlib模块 用于加密相关的操作,代替md5模块和sha模块,主要提供SHA1,SHA224,SSHA256,SHA384,SHA512,MD5算法 直接看代码案例: ---------md5- ...
随机推荐
- Python unittest excel数据驱动
安装xlrd 下载地址:https://pypi.python.org/pypi/xlrd 安装ddt 下载地址:https://pypi.python.org/pypi/ddt/1.1.0 clas ...
- Remove “Quick Access” entry in Eclipse Juno
Here is a quick hack which doesn't require any plugin installation, instead you just need to add a f ...
- sql server2008本地连接选择windows身份验证无法登陆的解决办法
1.安装完sqlserver数据库,本地连接登录不了 解决办法:进入cmd,输入net start mssqlserver 服务启动后,再次用windows身份验证就可以登陆本地数据库了
- c# 数据拼接成键值对格式
public static object FindLayoutTypes() { //地鼓.地裂.墙裂.井水.泉水 var sb = new StringBuilder(); sb.Append(ge ...
- 新手C#面向对象的学习2018.08.06
class Person//声明一个Person类 { //类中的声明与Main中不同,类中声明的是字段而不是函数. public string gender; public string name= ...
- 关于html与body的高度问题
转自https://blog.csdn.net/javaloveiphone/article/details/51098972 一.html,body{height:100%} 今天看到一个CSS样式 ...
- Spring分配置文件开发
---------------------siwuxie095 Spring 分配置文件开发 Spring 分配置文件开 ...
- Master节点部署
一.部署Kubernetes API服务部署 准备安装包 [root@linux-node1 ~]# cd /usr/local/src/kubernetes [root@linux-node1 ku ...
- eclipse中的.project 和 .classpath文件的具体作用(综合):
.project是项目文件,项目的结构都在其中定义,比如lib的位置,src的位置,classes的位置 .classpath的位置定义了你这个项目在编译时所使用的$CLASSPATH 这些文件你用文 ...
- Java程序设计11——异常处理
1 概述 异常机制已经成为判断一门编程语言是否成熟的标准,除了传统的像C语言没有提供异常机制之外,目前主流的编程语言如Java.Ruby.Python都提供了成熟的异常机制.异常机制可以使程序中异常处 ...