Base64和StrToByte
1 Function Base64Encode(inData As String) As String
2 Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
3 Dim cOut As String, sOut As String, i As Long
4 Dim Bytes() As Byte
5 Dim t As String
6 Dim iLen As Long
7 Dim sGroup As String
8 t = StrConv(inData & "..", vbFromUnicode)
9 Bytes = t
10 iLen = UBound(Bytes) - 2
11 Bytes(iLen + 1) = 0
12 Bytes(iLen + 2) = 0
13 sOut = ""
14 For i = 0 To iLen Step 3
15 sGroup = Oct(&H10000 * CLng(Bytes(i)) + &H100 * CLng(Bytes(i + 1)) + Bytes(i + 2))
16 sGroup = String(8 - Len(sGroup), "0") & sGroup
17 sOut = sOut + 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)
18 Next
19 Select Case iLen Mod 3
20 Case 0:
21 sOut = Left(sOut, Len(sOut) - 2) + "=="
22 Case 1:
23 sOut = Left(sOut, Len(sOut) - 1) + "="
24 End Select
25 Base64Encode = sOut
26 End Function
27
28
29
30 'StrToByte
31 Function StrToByte(s As String)
32 Dim Bytes() As Byte
33 Dim t
34 t = StrConv(s, vbFromUnicode)
35 Bytes = t
36 StrToByte = Bytes
37 End Function
38
39
2 Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
3 Dim cOut As String, sOut As String, i As Long
4 Dim Bytes() As Byte
5 Dim t As String
6 Dim iLen As Long
7 Dim sGroup As String
8 t = StrConv(inData & "..", vbFromUnicode)
9 Bytes = t
10 iLen = UBound(Bytes) - 2
11 Bytes(iLen + 1) = 0
12 Bytes(iLen + 2) = 0
13 sOut = ""
14 For i = 0 To iLen Step 3
15 sGroup = Oct(&H10000 * CLng(Bytes(i)) + &H100 * CLng(Bytes(i + 1)) + Bytes(i + 2))
16 sGroup = String(8 - Len(sGroup), "0") & sGroup
17 sOut = sOut + 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)
18 Next
19 Select Case iLen Mod 3
20 Case 0:
21 sOut = Left(sOut, Len(sOut) - 2) + "=="
22 Case 1:
23 sOut = Left(sOut, Len(sOut) - 1) + "="
24 End Select
25 Base64Encode = sOut
26 End Function
27
28
29
30 'StrToByte
31 Function StrToByte(s As String)
32 Dim Bytes() As Byte
33 Dim t
34 t = StrConv(s, vbFromUnicode)
35 Bytes = t
36 StrToByte = Bytes
37 End Function
38
39