问题
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