AES padding and writing the ciphertext to a disk file

前端 未结 1 1778
一向
一向 2021-01-22 12:15

I have a string which I encrypt with the following mehtod in C++ using Crypto++:

std::ifstream t(filename); //File to be          


        
相关标签:
1条回答
  • 2021-01-22 12:25

    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());
    
    0 讨论(0)
提交回复
热议问题