I have a wstring that has a base 64 string. I need to extract a byte array from this base 64 string. How can I do this? I am implementing a COM Server in C++. Please help
How to convert a base 64 string to byte array in C++?
Collapse
X
-
Basically, I have a .Net component (in C#) that would send the stream of bytes to my COM server after converting it into a base 64 string as follows:
This string is recieved in my C++ COM Server in a function called NotifyData(BSTR myDataByteStrea m). The .Net Component basically calls on one of the interface functions ( NotifyData(BSTR myData) ) of Com server by passing this string as argument. I am currently implementing the function NotifyData in COM Server. I want to now extract the byte array out of this string in C++. My objective is to get back the byte array with elements 1 and 2 which is the original data in my COM Server.Code://.Net code byte[] arr = new byte[2]; arr[0] = 1; arr[1] = 2; string dataByteStream = Convert.ToBase64String(arr); //In this case the value of dataByteStream will be "AQI="
My function in COM Server looks like this:
Code:NotifyData(BSTR myData) { wstring myDataBytes = myData; //base64 string containing "AQI=" byte *pArr = new byte[2]; memset(pArr ,0,2); //Do something to get the original byte array into pArr such that pArr[0] = 1 and pArr[1] = 2 }Comment
-
This is not an answer. just a discussion
Why did you declare
myData as BSTR. cant you just define as string? cause in the calling function you are using string to store base64 dataCode:NotifyData(BSTR myData)
besides Base64 encoded data only contain ASCII data not multibyte data is present there. To understand base64 please check base64 RFC.
even though wstring will not change the data that would be passed to NotifyData. but (I am not sure) wouldnt it make type casting error?
by the way what is wstring?
in visual C i have used wchar_t. this is 16bit in wchar_t data is stored as two byte. say if you store 'a' to wchar_t it would be equivalent to "0a"(char[2]).Comment
Comment