关于MD5sum [英] Regarding MD5sum

查看:73
本文介绍了关于MD5sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我在文本模式和二进制模式下打开文件时,我的MD5sum.exe显示不同的结果
模式.

即打开(文件路径,"r");

open(filepath,"rb");

我可以知道为什么需要使用
以二进制方式打开文件以创建校验和的原因吗? MD5算法.

同样,检查消息摘要对两个结果都显示确定".这让我感到困惑.
非常感谢.

Hi,

My MD5sum.exe is showing different results when i am opening the file in text mode and binary
mode.

i.e., open (filepath, "r");

open(filepath, "rb");

May i know the reason why files need to be opened in binary mode for checksum creation using
MD5 algorithm.

Also the check Message digest is showing OK for both the outcomes. This is confusing me.
Thank you very much.

推荐答案

以二进制模式打开文件时,您将完全像在磁盘上一样读取它:字节流. 当您以文本模式打开文件时,可能不会,具体取决于您的操作系统.对于基于Unix的系统,没有什么区别,但是对于DOS或Windows,回车符存储为两个字符"CR"(返回行首)和"LF"(输入新行),并转换为单个字符在文本模式下阅读时,字符"\ n"-而在书写时翻译则相反.

由于获得的数据不同,因此将获得不同的MD5哈希值.

顺便说一句:您知道您不应该将MD5用于新的应用程序吗?正式将其分类为残破",而应使用SHA.
When you open a file in binary mode, you will read it exactly as on the disk: a stream of bytes.
When you open a file in text mode you may not, depending on your operating system. With Unix based systems, there is no difference, however with DOS or Windows carriage returns are stored as two characters ''CR'' (return to start of line) and "LF" (Feed a new line) and are translated into a single character ''\n'' when reading in text mode - and the translation goes the other way on writing.

Since you get different data, you will get different MD5 hashes.

BTW: You do know you shouldn''t use MD5 for new applications? It is officially classed as "broken", and SHA should be used instead.


这篇关于关于MD5sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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