Sub test()
Dim bytArr(2) As Byte, txt As String
bytArr(0) = 94
bytArr(1) = 2
bytArr(2) = 255
txt = ByteToString(bytArr)
d = StringToByte(txt)
T = StringToSplite(txt)
b = ByteToTableau(bytArr)
End Sub
Function Base64Encoding(Buffer() As Byte) As String
With CreateObject("MSXML2.DOMDocument") '.DOMDocument
With .createElement("b64") 'MSXML2.IXMLDOMElement
.DataType = "bin.base64"
.nodeTypedValue = Buffer
Base64Encoding = .Text
End With
End With
End Function
Function Base64Decoding(Texte As String) As Byte()
With CreateObject("MSXML2.DOMDocument") '.DOMDocument
With .createElement("b64") 'MSXML2.IXMLDOMElement
.DataType = "bin.base64"
.Text = Texte
Base64Decoding = .nodeTypedValue
End With
End With
End Function
Function ByteToString(Buffer() As Byte) As String
For Each b In Buffer
ByteToString = ByteToString & IIf(Len(Hex$(b)) = 1, "0" & Hex$(b), Hex$(b))
Next
End Function
Function ByteToTableau(Buffer() As Byte) As String()
Dim b() As String, i As Integer, C As Integer
ReDim b(UBound(Buffer))
For i = 0 To UBound(Buffer)
b(i) = IIf(Len(Hex$(Buffer(i))) = 1, "0" & Hex$(Buffer(i)), Hex$(Buffer(i)))
Next
ByteToTableau = b
End Function
Function StringToByte(T As String) As Byte()
Dim b() As Byte, i As Integer, C As Integer
ReDim b((Len(T) / 2) - 1)
For i = 1 To Len(T) Step 2
b(C) = "&h" & Mid(T, i, 2)
C = C + 1
Next
StringToByte = b
End Function
Function StringToSplite(T As String) As String()
Dim b() As String, i As Integer, C As Integer
ReDim b((Len(T) / 2) - 1)
For i = 1 To Len(T) Step 2
b(C) = Mid(T, i, 2)
C = C + 1
Next
StringToSplite = b
End Function
Function LireFichierToByte(Fichier) As Byte()
Dim Buffer() As Byte, intFileNumber, Fso As Object, objXML As Object, objNode As Object
intFileNumber = FreeFile
Set Fso = CreateObject("Scripting.FileSystemObject")
ReDim Buffer(Fso.GetFile(Fichier).Size)
Set Fso = Nothing
Open Fichier For Binary As #intFileNumber
While Not EOF(intFileNumber)
Get #intFileNumber, , Buffer
Wend
LireFichierToByte = Buffer
End Function
Sub EcrireFichierToByte(Buffer() As Byte, Fichier)
Dim intFileNumber, Fso As Object, objXML As Object, objNode As Object
intFileNumber = FreeFile
Open Fichier For Binary As #intFileNumber
Put #intFileNumber, , Buffer
End Sub