| 4256 |
dpurdie |
1 |
'=====================================================
|
|
|
2 |
' Base64Encode
|
|
|
3 |
' Used in http Basic Authentication
|
|
|
4 |
'
|
|
|
5 |
' ripped from: 'http://www.pstruh.cz/tips/detpg_Base64Encode.htm
|
|
|
6 |
' rfc1521
|
|
|
7 |
' 2001 Antonin Foller, PSTRUH Software, http://pstruh.cz
|
|
|
8 |
'=====================================================
|
|
|
9 |
'
|
|
|
10 |
'------------ Functions -----------------------
|
|
|
11 |
Function Base64Encode(inData)
|
|
|
12 |
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
|
|
13 |
Dim sOut, I
|
|
|
14 |
|
|
|
15 |
'For each group of 3 bytes
|
|
|
16 |
For I = 1 To Len(inData) Step 3
|
|
|
17 |
Dim nGroup, pOut
|
|
|
18 |
|
|
|
19 |
'Create one long from this 3 bytes.
|
|
|
20 |
nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
|
|
|
21 |
&H100 * MyASC(Mid(inData, I + 1, 1)) + _
|
|
|
22 |
MyASC(Mid(inData, I + 2, 1))
|
|
|
23 |
|
|
|
24 |
'Oct splits the long To 8 groups with 3 bits
|
|
|
25 |
nGroup = Oct(nGroup)
|
|
|
26 |
|
|
|
27 |
'Add leading zeros
|
|
|
28 |
nGroup = String(8 - Len(nGroup), "0") & nGroup
|
|
|
29 |
|
|
|
30 |
'Convert To base64
|
|
|
31 |
pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
|
|
|
32 |
Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
|
|
|
33 |
Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
|
|
|
34 |
Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)
|
|
|
35 |
|
|
|
36 |
'Add the part To OutPut string
|
|
|
37 |
sOut = sOut + pOut
|
|
|
38 |
|
|
|
39 |
Next
|
|
|
40 |
Select Case Len(inData) Mod 3
|
|
|
41 |
Case 1: '8 bit final
|
|
|
42 |
sOut = Left(sOut, Len(sOut) - 2) + "=="
|
|
|
43 |
Case 2: '16 bit final
|
|
|
44 |
sOut = Left(sOut, Len(sOut) - 1) + "="
|
|
|
45 |
End Select
|
|
|
46 |
Base64Encode = sOut
|
|
|
47 |
End Function
|
|
|
48 |
|
|
|
49 |
Function MyASC(OneChar)
|
|
|
50 |
If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
|
|
|
51 |
End Function
|
|
|
52 |
'-- End of File
|