Option Explicit'************************************************************************************* 'Base 64 Encoding class ' 'Author: Wil Johnson ' [email protected] ' 'Version: 1.1 ' 'Date: 3/21/2000 ' 'Notes: ' This code is for example purposes only, and is provided as-is. While it has ' worked well under limited testing, the current error handling is minimal and ' should be expanded upon before release into a production environment. Please ' report all bugs found to the author for correction, even if you have already ' corrected them yourself. ' ' Again, this code is a rough draft. Feel free to use it, but do so at your own ' risk. These release notes must also remain intact. ' '************************************************************************************* Private m_bytIndex(0 To 63) As Byte Private m_bytReverseIndex(0 To 255) As BytePrivate Const k_bytEqualSign As Byte = 61Private Const k_bytMask1 As Byte = 3 '00000011 Private Const k_bytMask2 As Byte = 15 '00001111 Private Const k_bytMask3 As Byte = 63 '00111111Private Const k_bytMask4 As Byte = 192 '11000000 Private Const k_bytMask5 As Byte = 240 '11110000 Private Const k_bytMask6 As Byte = 252 '11111100Private Const k_bytShift2 As Byte = 4 Private Const k_bytShift4 As Byte = 16 Private Const k_bytShift6 As Byte = 64 Private Const k_lMaxBytesPerLine As Long = 152Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _ ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
Public Function Encode(ByRef sInput As String) As String If sInput = "" Then Exit Function Dim bytTemp() As Byte bytTemp = StrConv(sInput, vbFromUnicode) Encode = EncodeArr(bytTemp) End FunctionPublic Function EncodeFromFile(sFileName As String) As String On Error GoTo ErrorHandler: Dim bytFile() As Byte Dim iFile As Integer
'get new file handle iFile = FreeFile Open sFileName For Binary As #iFile 'size the array to the size of the file ReDim bytFile(0 To LOF(iFile) - 1) As Byte
MsgBox LOF(iFile)
'get everything in the file bytFile = Input(LOF(iFile), #iFile) Close #iFile
'encode it MsgBox bytFile
EncodeFromFile = EncodeArr(bytFile)
GoTo Done:
ErrorHandler: EncodeFromFile = "" Resume Done:Done: On Error Resume Next Close #iFile
email:[email protected]
'Base 64 Encoding class
'
'Author: Wil Johnson
' [email protected]
'
'Version: 1.1
'
'Date: 3/21/2000
'
'Notes:
' This code is for example purposes only, and is provided as-is. While it has
' worked well under limited testing, the current error handling is minimal and
' should be expanded upon before release into a production environment. Please
' report all bugs found to the author for correction, even if you have already
' corrected them yourself.
'
' Again, this code is a rough draft. Feel free to use it, but do so at your own
' risk. These release notes must also remain intact.
'
'*************************************************************************************
Private m_bytIndex(0 To 63) As Byte
Private m_bytReverseIndex(0 To 255) As BytePrivate Const k_bytEqualSign As Byte = 61Private Const k_bytMask1 As Byte = 3 '00000011
Private Const k_bytMask2 As Byte = 15 '00001111
Private Const k_bytMask3 As Byte = 63 '00111111Private Const k_bytMask4 As Byte = 192 '11000000
Private Const k_bytMask5 As Byte = 240 '11110000
Private Const k_bytMask6 As Byte = 252 '11111100Private Const k_bytShift2 As Byte = 4
Private Const k_bytShift4 As Byte = 16
Private Const k_bytShift6 As Byte = 64
Private Const k_lMaxBytesPerLine As Long = 152Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
Public Function Encode(ByRef sInput As String) As String
If sInput = "" Then Exit Function
Dim bytTemp() As Byte
bytTemp = StrConv(sInput, vbFromUnicode)
Encode = EncodeArr(bytTemp)
End FunctionPublic Function EncodeFromFile(sFileName As String) As String
On Error GoTo ErrorHandler:
Dim bytFile() As Byte
Dim iFile As Integer
'get new file handle
iFile = FreeFile Open sFileName For Binary As #iFile
'size the array to the size of the file
ReDim bytFile(0 To LOF(iFile) - 1) As Byte
MsgBox LOF(iFile)
'get everything in the file
bytFile = Input(LOF(iFile), #iFile)
Close #iFile
'encode it
MsgBox bytFile
EncodeFromFile = EncodeArr(bytFile)
GoTo Done:
ErrorHandler:
EncodeFromFile = ""
Resume Done:Done:
On Error Resume Next
Close #iFile
End Function