i'm trying to achieve the following:
In order to make sure the client machine holds sensitive data (in SecureString) as least as possible:
- Pin a byte array to memory holding a BSTR of the sensitive string (SecureString)
- transfer the sensitive data byte by byte using WCF (clearing each byte every send)
- after everything is received, the server needs to decode the bytes and right back into strings
i'm very concered about encoding - i understand that C# holds strings data as UTF-16, but is it possible that it will not be interpreted well when doing the following?:
- client machine converts to BSTR -> into bytes -> sending over the wire (WCF)
- server gets the BSTR array, and converts it back to string
should i worry about encoding? thanks!
=== EDIT - possible solution===
After consulting with EBrown, he found that microsoft uses the following BOM: https://msdn.microsoft.com/en-us/library/windows/desktop/dd374101%28v=vs.85%29.aspx
to convert into BSTR Bytes, i'm using the following method (it's a bit changed internally): https://stackoverflow.com/a/25190648/1845545
And, because C# uses UTF-16 encoding, i'll convert it back using: Encoding.Unicode.GetString(bt);