Access编程交流网
  • 设为首页|收藏本站|繁体中文|手机版
  •     
  • Access培训-Access开发平台-Access行业开发

  • 首页
  • 资讯
  • 技巧
  • 源码
  • 行业
  • 资源
  • 活动
  • 关于

技巧

ACCESS数据库

启动/设置/选项/背景

修复/压缩

安全/加密/解密

快捷键

版本升级/其它等

数据表

命名方式/设计规范

表设计

查询

Sql语言基础

选择查询

更新查询

删除查询

追加查询

生成表查询

交叉表查询

SQL特定查询

查询参数

查询综合应用

界面/窗体/控件

标签

文本框

命令按钮

组合框/列表框

选项组/复选框/选项按钮

选项卡

子窗体

窗体本身/综合应用

其它

报表打印

报表设计

高级报表

模块/函数/VBA/API/系统

VBA基础

内置函数

调试/跟踪/Debug

模块/类模块

API/COM/系统相关

字符数字日期

网络通信游戏

加密解密安全

文件处理

经典算法

宏/菜单/工具栏/功能区

宏/脚本

菜单/工具栏

功能区/Ribbon

图表/图形/图像/多媒体

图表

图形/图像

音频

视频/动画

DAO/链接表/ADO/ADP

DAO/链接表/ODBC

ADO/RDO

ADP

ActiveX/第三方控件/插件

Treeview树控件

ListView列表控件

Toolbar工具栏控件

微软其它控件

Dbi-Tech

CodeJock

Grid++Report

FastReport

ComponentOne

加载项/插件/Addin

OFFICE集成/导入导出/交互

Excel导入导出/交互

Word导入导出/交互

PPT交互

Outlook控制/邮件

Text文本文件/INI/CSV

PDF/SWF/XML格式

CAD格式

Sharepoint/其它Office

SqlServer/其它数据库

表

视图

存储过程/触发器

函数

用户/权限/安全

调试/维护

SqlServer其它/综合

发布/打包/文档/帮助

开发版/运行时

打包/发布/部署

开发文档/帮助制作

Access完整行业系统

采购管理系统

销售管理系统

仓库管理系统

人力资源管理HRM

CRM管理系统

MRP/ERP管理系统

BRP/流程优化

其它管理系统

心得/经验/绝招
其它/杂项
Excel技巧

Excel应用与操作

Excel开发编程

Word技巧

Word应用与操作

Word开发编程

Outlook技巧

Outlook应用与操作

Outlook开发编程

热门文章

  • 限制软件试用次数及时间
  • Access处理加了密码的..
  • Access 2003 进..
  • 创建一个带密码的Acces..
  • Access限制数据库的试..
  • 获取字符的Unicode编..

最新文章

  • 获取字符的Unicode编..
  • Access对数据表进行加..
  • Access 下Base6..
  • Access VBA可用的..
  • 获取电脑的网卡物理地址
  • 在 Access 2010..

联系方式

Access交流网(免费Access交流)

QQ:18449932 

网  址:www.access-cn.com

当前位置:首页 > 技巧 > 模块/函数/VBA/API/系统 > 加密解密安全
加密解密安全

base64编码、解码函数

base64编码、解码函数

Asp:base64编码、解码函数

--------------------------------------------------------------------------------

 

这是我看完几个base64编码、解码函数后自己改写的。
因为,在中文操作系统的VBscript中,使用的是unicode字符集,所以
很多base64编码、解码函数在理论上是正确的,但实际不能运行!

sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 
sBASE_64_CHARACTERS = strUnicode2Ansi(sBASE_64_CHARACTERS)

Function strUnicodeLen(asContents)
'计算unicode字符串的Ansi编码的长度
asContents1="a"&asContents
len1=len(asContents1)
k=0
for i=1 to len1
asc1=asc(mid(asContents1,i,1))
if asc1<0 then asc1=65536+asc1
if asc1>255 then
k=k+2
else
k=k+1
end if
next
strUnicodeLen=k-1
End Function

Function strUnicode2Ansi(asContents)
'将Unicode编码的字符串,转换成Ansi编码的字符串
strUnicode2Ansi=""
len1=len(asContents)
for i=1 to len1
varchar=mid(asContents,i,1)
varasc=asc(varchar)
if varasc<0 then varasc=varasc+65536
if varasc>255 then
varHex=Hex(varasc)
varlow=left(varHex,2)
varhigh=right(varHex,2)
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=0 then exit function
for i=1 to len1
varchar=midb(asContents,i,1)
varasc=ascb(varchar)
if varasc > 127 then 
strAnsi2Unicode = strAnsi2Unicode & chr(ascw(midb(asContents,i+1,1) & varchar))
i=i+1
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<1 then 
Base64encode=""
exit Function
end if

m3=Len1 Mod 3 
If M3 > 0 Then asContents = asContents & String(3-M3, chrb(0)) 
'补足位数是为了便于计算

IF m3 > 0 THEN 
len1=len1+(3-m3)
len2=len1-3
else
len2=len1
end if

lsResult = "" 

For lnPosition = 1 To len2 Step 3 
lsGroup64 = "" 
lsGroupBinary = Midb(asContents, lnPosition, 3) 

Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3 
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15 
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1)) 

Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1) 
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1) 
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1) 
Char4 = Midb(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1) 
lsGroup64 = Char1 & Char2 & Char3 & Char4 

lsResult = lsResult & lsGroup64 
Next 

'处理最后剩余的几个字符
if M3 > 0 then
lsGroup64 = "" 
lsGroupBinary = Midb(asContents, len2+1, 3) 

Byte1 = Ascb(Midb(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3 
Byte2 = Ascb(Midb(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15 
Byte3 = Ascb(Midb(lsGroupBinary, 3, 1)) 

Char1 = Midb(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1) 
Char2 = Midb(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1) 
Char3 = Midb(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1) 

if M3=1 then
lsGroup64 = Char1 & Char2 & ChrB(61) & ChrB(61) '用=号补足位数
else
lsGroup64 = Char1 & Char2 & Char3 & ChrB(61) '用=号补足位数
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 4

if len1 < 1 or M4 > 0 then
'字符串长度应当是4的倍数
Base64decode = "" 
exit Function 
end if

'判断最后一位是不是 = 号
'判断倒数第二位是不是 = 号
'这里m4表示最后剩余的需要单独处理的字符个数
if midb(asContents, len1, 1) = chrb(61) then m4=3 
if midb(asContents, len1-1, 1) = chrb(61) then m4=2

if m4 = 0 then
len2=len1
else
len2=len1-4
end if

For lnPosition = 1 To Len2 Step 4 
lsGroupBinary = "" 
lsGroup64 = Midb(asContents, lnPosition, 4) 
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1 
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1 
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1 
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1 
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF) 
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF) 
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63)) 
lsGroupBinary = Byte1 & Byte2 & Byte3 

lsResult = lsResult & lsGroupBinary 
Next 

'处理最后剩余的几个字符
if M4 > 0 then 
lsGroupBinary = "" 
lsGroup64 = Midb(asContents, len2+1, m4) & chrB(65) 'chr(65)=A,转换成值为0
if M4=2 then '补足4位,是为了便于计算 
lsGroup64 = lsGroup64 & chrB(65) 
end if
Char1 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 1, 1)) - 1 
Char2 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 2, 1)) - 1 
Char3 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 3, 1)) - 1 
Char4 = InStrb(sBASE_64_CHARACTERS, Midb(lsGroup64, 4, 1)) - 1 
Byte1 = Chrb(((Char2 And 48) \ 16) Or (Char1 * 4) And &HFF) 
Byte2 = lsGroupBinary & Chrb(((Char3 And 60) \ 4) Or (Char2 * 16) And &HFF) 
Byte3 = Chrb((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63)) 

if M4=2 then
lsGroupBinary = Byte1
elseif M4=3 then
lsGroupBinary = Byte1 & Byte2
end if

lsResult = lsResult & lsGroupBinary 
end if

Base64decode = lsResult 

End Function
 

发布人:不详-goodidea  
分享到:
点击次数:  更新时间:2003-12-21 00:41:42  【打印此页】  【关闭】
上一条:了解 Microsoft Access 安全性  下一条:加密后台数据库的方法



相关文章

  • • 获取字符的Unicode编码、Ascii码、及各种编码转换加密解密
  • • Access对数据表进行加密解密
  • • Access 下Base64位加密解密类模块(支持中文加解密和特殊符号)
  • • Access VBA可用的Base64编码/解码模块
  • • 获取电脑的网卡物理地址
  • • 在 Access 2010 中设置或更改 Access 2003 用户级安全机制
  • • ACCESS安全机制中的工作组管理员文件如果防止被替换
  • • ACCESS丢失MDW,还能还原用户与用户组及权限相关信息吗

热门文章

  • [2008-10-22] Access处理加了密码的MDB数据库文件access数据库
  • [2003-12-13] 找回忘了的密码的原理access数据库
  • [2003-12-12] 在ADP/ADE中禁止SHIFT键的方法access数据库
  • [2003-12-20] Access处理加了密码的MDB文件access数据库
  • [2003-12-12] 破解Access(*.mdb)目前所有版本的密码access数据库
  • [2004-08-18] Access限制数据库的试用天数access数据库

热门产品

公司动态|在线留言|在线反馈|友情链接|会员中心|站内搜索|网站地图

中山市天鸣科技发展有限公司 版权所有 1999-2023 粤ICP备10043721号

QQ:18449932

Access应用 Access培训 Access开发 Access平台

access|数据库|access下载|access教程|access视频|access软件

Powered by MetInfo 5.3.12 ©2008-2026  www.metinfo.cn