I have an unmanaged C dll I call from a C# class library that encrypts a string value into an encrypted string that contains non-ascii characters. I need to take the data and write its binary values to a file but C# treats text as strings rather than a byte[]. The encrypted value commonly contains special characters (\r, \O, etc). When I do this converting the returned string to C# using some type of codeset (ascii, utf-7, utf-16) it writes the special character values as the windows interpreted values instead their actual binary representation.
My question is how can I pull the data from the unmanaged dll into a byte[] rather than a string so I can write that to file using the BinaryWriter?
Thanks.