![]() You can see the roundtrip by doing echo 'Bye world!!' |. Note that I found that I needed to ensure padding was done to BLOCKSIZE, and as such I added a length field to store the actual size of the plaintext to avoid trailing garbage after decryption. QUJDRAwAAABCaDMrpG0WEYePd7fI0wsHAQoNkUl1CjIBCg2RSXUKMg= Results in a 40 byte file (sig + length + ciphertext = 4 + 4 + 32 = 40), in base64: base64 test.bin Update So, I've made an encryptor.cpp now too. Out.write(plaintext.data(), plaintext.size()) Std::ofstream out("out.bin", std::ios::binary) Std::vector plaintext(ciphertext.size()) ĭecryption.ProcessData(reinterpret_cast(plaintext.data()), ciphertext.data(), plaintext.size()) std::copy_n(std::istreambuf_iterator(data), 32, std::back_inserter(ciphertext)) Īssert(ciphertext.size() % CryptoPP::Blowfish::BLOCKSIZE = 0) ĬryptoPP::ECB_Mode::Decryption decryption(key.data(), key.size()) This is a bug if(fread(header, sizeof(header), 1, data) if you're using C++, why use cstdlib, cstdio and cstring in the first place?.you should prefer unsigned char for binary data (fewer pitfalls to do with sign extension and undefined behaviour on overflow).you don't validate that fread actually read 4 bytes.you should use memcmp instead of strcmp.fopen should use "rb" and "wb" for binary mode.If(fread(type, sizeof(type) - 1, 1, data) key ĮCB_Mode::Decryption decryption(key.data(), key.size()) įwrite (out, sizeof(byte), sizeof(out), outer) īut this is not decrypting the data correctly. So i wrote this code to be able to do this: string file = "C:\\test.bin" In my file, the first 4 bytes is describing the file format, the 32 bytes after it is the header, which is encrypted with Blowfish. I have been trying all day today to finde out how to read from a binary file and decrypt it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |