I need to encrypt an array of UTF16 characters and eventually decrypt back to the UTF16 array. To do this I need to convert the UTF16 array to an array of UTF8 characters, but in such a way that each UTF16 character becomes equivalent to the two characters which comprises the UTF16 character. When I decrypt back I need to take my array of UTF8 characters and convert it to the equivalent array of UTF16 characters. How do I do that using the Win32 API ? I do not think the WideCharToMultiByte/MultiByteToWideChar will work properly, as I believe they do conversions rather than equivalents.
Edward Diener wrote: > I need to encrypt an array of UTF16 characters and eventually decrypt > back to the UTF16 array. To do this I need to convert the UTF16 array to > an array of UTF8 characters, but in such a way that each UTF16 character > becomes equivalent to the two characters which comprises the UTF16 > character. When I decrypt back I need to take my array of UTF8 > characters and convert it to the equivalent array of UTF16 characters. > > How do I do that using the Win32 API ? > > I do not think the WideCharToMultiByte/MultiByteToWideChar will work > properly, as I believe they do conversions rather than equivalents. I realized I can use the LOBYTE, HIBYTE, and MAKEWORD macros to achieve what I want.
> To do this I need to convert the UTF16 array to > an array of UTF8 characters, but in such a way that each UTF16 character > becomes equivalent to the two characters which comprises the UTF16 > character. UTF-8 uses between 1 and 4 bytes, not 2. How can a character be equivalent to two characters? > I do not think the WideCharToMultiByte/MultiByteToWideChar will work > properly, as I believe they do conversions rather than equivalents. I don't understand what you mean by "equivalents" WideCharToMultiByte/MultiByteToWideChar will do conversion, that is valid and will give you UTF-8. If you want something else, the result is not UTF-8 anymore. -- Mihai Nita [Microsoft MVP, Visual C++] http://www.mihai-nita.net ------------------------------------------ Replace _year_ with _ to get the real email
> I realized I can use the LOBYTE, HIBYTE, and MAKEWORD macros to achieve > what I want. That has absolutely nothing to do with UTF-8 And for what you want you don't need any macros, just cast the pointer to WCHAR to a pointer to BYTE. -- Mihai Nita [Microsoft MVP, Visual C++] http://www.mihai-nita.net ------------------------------------------ Replace _year_ with _ to get the real email
Edward Diener writes: > To do this I need to convert the UTF16 array to an array of > UTF8 characters, but in such a way that each UTF16 character > becomes equivalent to the two characters which comprises the > UTF16 character. That encoding is called CESU-8.