Function Base64Encode( ByVal InBuff As String, ByVal B64_Alpha As String) As String
'--- Base64 Encode
Local OutBuff,T As String
Local I,J,K,tt As Long
' tt 4 byte work buffer
If B64_Alpha="" Then
B64_Alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
End If
T = Space$(4) 'octet work string
J=0 'input char. pointer
Do While J<Len(InBuff)
tt=0 'clear work buffer
K=1 'output counter
For I=1 To 3 'load up 3 ASCII char.
Shift Left tt,8 'make room for it in buffer
If J<Len(InBuff) Then 'any remaining?
Incr J 'next char.
Incr K 'count the required output
tt = tt Or Asc(InBuff,J)'add into buffer
End If
Next
Rotate Left tt,14 'roll around to start of buffer
Mid$(T,3)="==" 'pre-pad the octet string in case K<4
For I=1 To K 'build the octet
Asc(T,I) = Asc(B64_Alpha, (tt And 63&)+1&) 'convert 6 bits to B64
' alphabet:
Rotate Left tt,6 'do next one
Next
OutBuff=OutBuff+T 'build output one octet at a time
Loop
Function = OutBuff 'return the encoded string
End Function