這是一個(gè)Base64編碼、解碼小工具(可破解迅雷下載地址)。采用本站原創(chuàng)的VB6下Base64編碼解碼算法。
Base64說(shuō)明
Base64是網(wǎng)絡(luò)上最常見(jiàn)的用于傳輸8Bit字節(jié)代碼的編碼方式之一,可用于在HTTP環(huán)境下傳遞較長(zhǎng)的標(biāo)識(shí)信息。在其他應(yīng)用程序中,也常常需要把二進(jìn)制數(shù)據(jù)編碼為適合放在URL(包括隱藏表單域)中的形式。此時(shí),采用Base64編碼不僅比較簡(jiǎn)短,同時(shí)也具有不可讀性,即所編碼的數(shù)據(jù)不會(huì)被人用肉眼所直接看到。
程序源碼:
Option Explicit
Private Const cstBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Private arrBase64() As String
'00100001 00100001 00100001 --源碼
'00001000 00010010 00000100 00100001 --Base64碼
Public Function Base64Encode(strSource As String) As String
On Error Resume Next
'適用于中、英文的Base64編碼/解碼VB6超精簡(jiǎn)版
If UBound(arrBase64) = -1 Then
arrBase64 = Split(StrConv(cstBase64, vbUnicode), vbNullChar)
End If
Dim arrB() As Byte, bTmp(2) As Byte, bT As Byte
Dim I As Long, J As Long
arrB = StrConv(strSource, vbFromUnicode)
J = UBound(arrB)
For I = 0 To J Step 3
Erase bTmp
bTmp(0) = arrB(I + 0)
bTmp(1) = arrB(I + 1)
bTmp(2) = arrB(I + 2)
bT = (bTmp(0) And 252) / 4
Base64Encode = Base64Encode & arrBase64(bT)
bT = (bTmp(0) And 3) * 16
bT = bT + bTmp(1) / 16
Base64Encode = Base64Encode & arrBase64(bT)
bT = (bTmp(1) And 15) * 4
bT = bT + bTmp(2) / 64
If I + 1 <= J Then
Base64Encode = Base64Encode & arrBase64(bT)
Else
Base64Encode = Base64Encode & "="
End If
bT = bTmp(2) And 63
If I + 2 <= J Then
Base64Encode = Base64Encode & arrBase64(bT)
Else
Base64Encode = Base64Encode & "="
End If
Next
End Function
Public Function Base64Decode(strEncoded As String) As String
'適用于中、英文的Base64編碼/解碼VB6超精簡(jiǎn)版
On Error Resume Next
Dim arrB() As Byte, bTmp(3) As Byte, bT As Long, bRet() As Byte
Dim I As Long, J As Long
arrB = StrConv(strEncoded, vbFromUnicode)
J = InStr(strEncoded & "=", "=") - 2
ReDim bRet(J - J / 4 - 1)
For I = 0 To J Step 4
Erase bTmp
bTmp(0) = (InStr(cstBase64, Chr(arrB(I))) - 1) And 63
bTmp(1) = (InStr(cstBase64, Chr(arrB(I + 1))) - 1) And 63
bTmp(2) = (InStr(cstBase64, Chr(arrB(I + 2))) - 1) And 63
bTmp(3) = (InStr(cstBase64, Chr(arrB(I + 3))) - 1) And 63
bT = bTmp(0) * 2 ^ 18 + bTmp(1) * 2 ^ 12 + bTmp(2) * 2 ^ 6 + bTmp(3)
bRet((I / 4) * 3) = bT / 65536
bRet((I / 4) * 3 + 1) = (bT And 65280) / 256
bRet((I / 4) * 3 + 2) = bT And 255
Next
Base64Decode = StrConv(bRet, vbUnicode)
End Function
- PC官方版
- 安卓官方手機(jī)版
- IOS官方手機(jī)版