linux下获取某个给定值/字符的md5值

简介

MD5信息摘要算法(英语全称:MD5 Message-Digest Algorithm 5),是一种被广泛使用的密码散列函数,可以产生出一个128位(16字节,十六进制长度就是32位)的散列值(hash value)或者说“指纹”(或称“报文摘要”,因此MD5也被称为摘要算法),不同的文件产生相同的报文摘要的可能性是非常非常之小的,因此常用于简单确认信息传输完整一致。MD5由美国密码学家罗纳德·李维斯特(Ronald Linn Rivest)设计,于1992年公开,用以取代MD4算法。这套算法的程序在 RFC 1321 标准中被加以规范。1996年后该算法被证实存在弱点,可以被加以破解,对于需要高度安全性的数据,建议改用其他安全算法。2004年,证实MD5算法无法防止碰撞(collision),因此不适用于高要求的安全性认证。

linuxUnix上,md5sum是用来计算和校验文件报文摘要的工具程序。一般来说,Linux自带md5sum工具,直接在命令行终端直接运行。

执行md5sum --help

Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.

  -b, --binary         read in binary mode
  -c, --check          read MD5 sums from the FILEs and check them
      --tag            create a BSD-style checksum
  -t, --text           read in text mode (default)
  Note: There is no difference between binary and text mode option on GNU system.

The following four options are useful only when verifying checksums:
      --quiet          don't print OK for each successfully verified file
      --status         don't output anything, status code shows success
      --strict         exit non-zero for improperly formatted checksum lines
  -w, --warn           warn about improperly formatted checksum lines

      --help     display this help and exit
      --version  output version information and exit

The sums are computed as described in RFC 1321.  When checking, the input
should be a former output of this program.  The default mode is to print
a line with checksum, a character indicating input mode ('*' for binary,
space for text), and name for each FILE.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'md5sum invocation

-b 或 --binary :把输入文件作为二进制文件看待。
-t 或 --text :把输入的文件作为文本文件看待(默认)。
-c 或 --check :用来从文件中读取md5信息检查文件的一致性。(不细说了参见info)
–status :这个选项和check一起使用,在check的时候,不输出,而是根据返回值表示检查结果。
-w 或 --warn :在check的时候,检查输入的md5信息又没有非法的行,如果有则输出相应信息。

作用

  1. 计算md5值
  2. 检查两个文件是否一样,通过比较两个文件的md5值是否一致
  3. 判断一个文件是否修改,通过和原始文件提供的md5值判断是否一致

linux下获取某个给定值/字符的md5值

例如:获取123456的md5值

echo -n "123456" | md5sum

得到如下结果:

e10adc3949ba59abbe56e057f20f883e -

echo一定要加-n选项,不加的话echo会自动输出换行符一起计算md5值导致不准

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GaoJamie

您的鼓励将是我更新的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值