How to properly work with file upon encoding and decoding it?

女生的网名这么多〃 提交于 2019-12-25 08:21:34

问题


It doesn't matter how I exactly encrypt and decode files. I operate with file as a char massive, everything is almost fine, until I get file, which size is not divide to 8 bytes. Because I can encrypt and decode file each round 8 bytes, because of particular qualities of algorithm (size of block must be 64 bit).

So then, for example, I face .jpg and tried simply add spaces to end of file, result file can't be opened ( ofc. with .txt files nothing bad happen).

Is any way out here?

If you want information about algorithm http://en.wikipedia.org/wiki/GOST_(block_cipher).

UPD: I can't store how many bytes was added, because initial file can be deleted or moved. And, what we are suppose to do then we know only key and have encrypted file.


回答1:


Do you need padding. The best way to do this would be to use PKCS#7.

However GOST is not so good, better using AES-CBC. There is an ongoing similar discussion in "python-channel".



来源:https://stackoverflow.com/questions/20504653/how-to-properly-work-with-file-upon-encoding-and-decoding-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!