
MultiByteToWideChar CP_UTF8, 0, sData, -1, VarPtr(aRetn(0)), nSize If nSize = 0 Or nSize = -1 Then Exit Function NSize = MultiByteToWideChar(CP_UTF8, 0, sData, -1, 0, 0) - 1 Public Function Utf8ToString(ByVal sData As Long) As Byte() ' Note: Len(sData) > 0 Private Declare Function WideCharToMultiByte Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long If retlen = 0 Then Base64Decode = "": Exit FunctionĬall CryptStringToBinaryA(VarPtr(b(0)), s, CRYPT_STRING_BASE64_ANY, VarPtr(ret(0)), retlen, 0, 0)īase64Decode = StrConv(LeftB(ret, retlen), vbUnicode)įunction Base64Encode(data() As Byte) As StringĬall CryptBinaryToStringA(VarPtr(data(0)), s, 1073741825, StrPtr(ret), retlen)Ĭall CryptBinaryToStringA(VarPtr(data(0)), s, 1073741825, VarPtr(ret(0)), retlen)īase64Encode = StrConv(LeftB(ret, retlen), vbUnicode)Ĭode: Private Declare Function MultiByteToWideChar Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long Private Const CRYPT_STRING_BASE64_ANY = &H6Ī = Base64Encode(StrConv("TestStr", vbFromUnicode))įunction Base64Decode(ByVal data As String) As StringĬall CryptStringToBinaryA(VarPtr(b(0)), s, CRYPT_STRING_BASE64_ANY, StrPtr(ret), retlen, 0, 0) Private Declare Function CryptStringToBinaryA Lib "crypt32.dll" (ByVal pszString As Long, ByVal cchString As Long, ByVal dwFlags As Long, ByVal pbBinary As Long, ByRef pcbBinary As Long, ByVal pdwSkip As Long, ByVal pdwFlags As Long) As Long


Code: Private Declare Function CryptBinaryToStringA Lib "crypt32.dll" (ByVal pbBinary As Long, ByVal cbBinary As Long, ByVal dwFlags As Long, ByVal pszString As Long, ByRef pcchString As Long) As Long
