如何正确处理文件编码和解码? [英] How to properly work with file upon encoding and decoding it?

查看:315
本文介绍了如何正确处理文件编码和解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我如何精确地加密和解码文件。我使用文件作为 char large 操作,一切都差不多,直到我得到文件,其大小不分为8个字节。因为我可以加密和解码文件每个8字节,因为特定的算法质量(块的大小必须是64位)。

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).

那么,例如,我面对 .jpg ,并尝试在文件末尾添加空格,结果文件

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).

这里有什么办法吗?

如果您需要有关算法的信息 http://en.wikipedia.org/wiki/GOST_ (block_cipher)

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

UPD:我无法存储添加的字节数,因为可以删除初始文件移动。

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.

推荐答案

你需要填充。
执行此操作的最佳方法是使用 PKCS#7 < a>。

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

但是GOST不是那么好,更好的使用AES-CBC。
有一个类似的
python-channel中的讨论

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

这篇关于如何正确处理文件编码和解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆