VB VBA ASP 可通用的基于Base64進(jìn)行加密和解密的函數(shù)
- 2017-09-20 08:00:00
- 網(wǎng)絡(luò) 轉(zhuǎn)貼
- 5348
VB VBA ASP 可通用的基于Base64進(jìn)行加密和解密的函數(shù)
可用于Access VBA 以及 Excel VBA對(duì)字符串 數(shù)據(jù)甚至文本文件進(jìn)行加密和解密,以保證您數(shù)據(jù)的安全。
先創(chuàng)建一個(gè)模塊,在模塊中添加如下代碼
OPTION EXPLICIT const BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" dim newline dim Base64EncMap(63) dim Base64DecMap(127) '初始化函數(shù) PUBLIC SUB initCodecs() ' 初始化變量 newline =vbCrlf ' 如果是ASP就改成這個(gè) "<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加密函數(shù) 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解密函數(shù) 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 ' 測(cè)試代碼 dim inp, encode inp = "1234567890" encode = base64Encode(inp) Debug.Print "加密前為:" & inp & vbCrlf Debug.Print "加密后為:" & encode & vbCrlf Debug.Print "解密后為:" & base64Decode(encode) & vbCrlf
分享
Access數(shù)據(jù)庫(kù)自身
- office課程播放地址及課程明細(xì)
- Excel Word PPT Access VBA等Office技巧學(xué)習(xí)平臺(tái)
- 將( .accdb) 文件格式數(shù)據(jù)庫(kù)轉(zhuǎn)換為早期版本(.mdb)的文件格式
- 將早期的數(shù)據(jù)庫(kù)文件格式(.mdb)轉(zhuǎn)換為 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數(shù)據(jù)庫(kù)引擎和訪問連接引擎以阻止對(duì)遠(yuǎn)程數(shù)據(jù)庫(kù)的訪問(remote table)
- Access 365 /Access 2019 數(shù)據(jù)庫(kù)中哪些函數(shù)功能和屬性被沙箱模式阻止(如未啟動(dòng)宏時(shí))
- Access Runtime(運(yùn)行時(shí))最全的下載(2007 2010 2013 2016 2019 Access 365)
Access VBA函數(shù)模塊
- access vba代碼太長(zhǎng),換行,分行的寫法
- VB6 VBA Access真正可用并且完美支持中英文的 URLEncode 與 URLDecode 函數(shù)源碼
- 自定義VB中的urlencode函數(shù),將URL中特殊部分進(jìn)行編碼
- Access 函數(shù)簡(jiǎn)化串接sql字符串,減少符號(hào)導(dǎo)致的書寫錯(cuò)誤
- vba完全關(guān)閉IE瀏覽器及調(diào)用IE瀏覽器的簡(jiǎn)單應(yīng)用
- 利用FollowHyperlink方法打開超鏈接提示“無(wú)法下載您要求的信息”的解決方案
- 在access中用代碼打開文本框中超鏈接地址
Access Activex第三方控件
- Activex控件或Dll 在某些電腦無(wú)法正常注冊(cè)的解決辦法(regsvr32注冊(cè)時(shí)卡住)
- office使用部分控件時(shí)提示“您沒有使用該ActiveX控件許可的問題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹控件(treeview) 64位Office下出現(xiàn)橫向滾動(dòng)條不會(huì)自動(dòng)定位的解決辦法
- Access中國(guó)樹控件 在win10電腦 節(jié)點(diǎn)行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹控件 ListView列表等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調(diào)用WebService(直接Post方式)并解析返回的XML
Access ADP Sql Server等
- 早期PB程序連接Sqlserver出現(xiàn)錯(cuò)誤
- MMC 不能打開文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由于文件不存在,不是一個(gè)MMC控制臺(tái),或者用后來的MMC版
- sql server連接不了的解決辦法
- localhost與127.0.0.1區(qū)別
- Roych的淺談數(shù)據(jù)庫(kù)開發(fā)系列(Sql Server)
- sqlserver 自動(dòng)備份對(duì)備份目錄沒有存取權(quán)限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業(yè)管理器 SQLServer2005_SSMSEE
Access 行業(yè)應(yīng)用開發(fā)
文章分類
聯(lián)系我們
聯(lián)系人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |