Вопрос

I need to read a large file of either text, binary, or combination, such as a JPEG file, encrypt it, and write it to a file. At some later time I will need to read the encrypted data, and decrypt it. The end goal is to verify that the decrypted data matches the original data. My problem is that with large files greater than 1Meg, I don't want to read and write character by character. I am targeting this code for a phone and I/O will cause too long a delay for the user. With a pure text file, using fread() and fwrite() convert the data to binary, and the result is different than the original. With a jpeg image, it appears that there is some textual content mixed in with the binary data. Is there a way to efficiently read in an arbitrary type of file and write it back in the original format? Or is character by character the only option? Or am I still out of luck?

Это было полезно?

Решение

After debugging it turned out that the decrypt function had the plain text and cipher text buffers assigned backwards. After swapping the buffer assignments, the decrypted results matched the original data. I originally thought that maybe reading the text as binary and then rewriting as binary would not appear as text, but I was wrong. Reading the entire file as binary works just fine.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top