I have a string which I encrypt with the following mehtod in C++ using Crypto++:
std::ifstream t(filename); //File to be
Based on the comment:
In C++ I save a file combined_file2 << encrypt(buffer.str()); which I read in my C# program string plaintext = Decrypt(File.ReadAllBytes(path));
I don't think embedded NULLs is causing problems from the encrypt
function since its returning a string
, and that includes an explicit length.
However, an embedded NULL and the way the file is being written to disk in C++ (or read from disk in C#) will be a problem since this will stop at the first embedded NULL: combined_file2 << encrypt(buffer.str())
.
Perhaps something like the following would be helpful:
StringSource ss(ciphertext, true /*pumpAll*/);
FileSink fs("my-encrypted-file.bin", true /*binary*/);
ss.TransferTo(fs);
If you are using a C++ stream, then use the write
method on the stream object:
ofstream combined_file2;
...
combined_file2.write(ciphertext.data(), ciphertext.size());