7,763
社区成员
发帖
与我相关
我的任务
分享
Function MyASC(OneChar)
If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function
Private Function Base64Encode(inData)
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim cOut, sOut, i
For i = 1 To Len(inData) Step 3
Dim nGroup As Long
Dim pOut, sGroup
nGroup = &H10000 * Asc(Mid(inData, i, 1)) + &H100 * MyASC(Mid(inData, i + 1, 1)) + MyASC(Mid(inData, i + 2, 1))
sGroup = Oct(nGroup)
sGroup = String(8 - Len(sGroup), "0") & sGroup
pOut = Mid(Base64, CLng("&o" & Mid(sGroup, 1, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 3, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 5, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 7, 2)) + 1, 1)
sOut = sOut + pOut
If (i + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
Next
Select Case Len(inData) Mod 3
Case 1:
sOut = Left(sOut, Len(sOut) - 2) + "=="
Case 2:
sOut = Left(sOut, Len(sOut) - 1) + "="
End Select
Base64Encode = sOut
End Function