本文对linux下md5sum命令和java中DigestUtils.md5Hex进行比较,要了解各自的本质,就需要深入源码来了解各自运行机制。

1.linux下md5sum命令的源码

a.查看md5sum命令的位置

b.查看md5sum在哪个package中

c.从上可以知道md5sum命令在coreutils包中,下载coreutils包。查看md5sum的源码在md5sum.c文件中,内容如下:

Java代码

/* Compute MD5 or SHA1 checksum of files or strings

Copyright (C) 1995-2002 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation; either version 2, or (at your option)

any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software Foundation,

Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

/* Written by Ulrich Drepper . */

#include

#include

#include

#include

#include "system.h"

#include "md5.h"

#include "sha.h"

#include "checksum.h"

#include "getline.h"

#include "closeout.h"

#include "error.h"

/* The official name of this program (e.g., no `g' prefix). */

#define PROGRAM_NAME (algorithm == ALG_MD5 ? "md5sum" : "shasum")

#define AUTHORS N_ ("Ulrich Drepper and Scott Miller")

/* Most systems do not distinguish between external and internal

text representations. */

/* FIXME: This begs for an autoconf test. */

#if O_BINARY

# define OPENOPTS(BINARY) ((BINARY) != 0 ? TEXT1TO1 : TEXTCNVT)

# define TEXT1TO1 "rb"

# define TEXTCNVT "r"

#else

# if defined VMS

# define OPENOPTS(BINARY) ((BINARY) != 0 ? TEXT1TO1 : TEXTCNVT)

# define TEXT1TO1 "rb", "ctx=stm"

# define TEXTCNVT "r", "ctx=stm"

# else

# if UNIX || __UNIX__ || unix || __unix__ || _POSIX_VERSION

# define OPENOPTS(BINARY) "r"

# else

/* The following line is intended to evoke an error.

Using #error is not portable enough. */

"Cannot determine system type."

# endif

# endif

#endif

#define DIGEST_TYPE_STRING(Alg) ((Alg) == ALG_MD5 ? "MD5" : "SHA1")

#define DIGEST_STREAM(Alg) ((Alg) == ALG_MD5 ? md5_stream : sha_stream)

#define DIGEST_BITS(Alg) ((Alg) == ALG_MD5 ? 128 : 160)

#define DIGEST_HEX_BYTES(Alg) (DIGEST_BITS (Alg) / 4)

#define DIGEST_BIN_BYTES(Alg) (DIGEST_BITS (Alg) / 8)

#define MAX_DIGEST_BIN_BYTES MAX (DIGEST_BIN_BYTES (ALG_MD5),

DIGEST_BIN_BYTES (ALG_SHA1))

/* The minimum length of a valid digest line. This length does

not include any newline character at the end of a line. */

#define MIN_DIGEST_LINE_LENGTH(Alg)

(DIGEST_HEX_BYTES (Alg) /* length of hexadecimal message digest */

+ 2 /* blank and binary indicator */

+ 1 /* minimum filename length */ )

/* Nonzero if any of the files read were the standard input. */

static int have_read_stdin;

/* The minimum length of a valid checksum line for the selected algorithm. */

static size_t min_digest_line_length;

/* Set to the length of a digest hex string for the selected algorithm. */

static size_t digest_hex_bytes;

/* With --check, don't generate any output.

The exit code indicates success or failure. */

static int status_only = 0;

/* With --check, print a message to standard error warning about each

improperly formatted checksum line. */

static int warn = 0;

/* Declared and set via one of the wrapper .c files. */

/* int algorithm = ALG_UNSPECIFIED; */

/* The name this program was run with. */

char *program_name;

static const struct option long_options[] =

{

{ "binary", no_argument, 0, 'b' },

{ "check", no_argument, 0, 'c' },

{ "status", no_argument, 0, 2 },

{ "string", required_argument, 0, 1 },

{ "text", no_argument, 0, 't' },

{ "warn", no_argument, 0, 'w' },

{ GETOPT_HELP_OPTION_DECL },

{ GETOPT_VERSION_OPTION_DECL },

{ NULL, 0, NULL, 0 }

};

void

usage (int status)

{

if (status != 0)

fprintf (stderr, _("Try `%s --help' for more information.n"),

program_name);

else

{

printf (_("

Usage: %s [OPTION] [FILE]...n

or: %s [OPTION] --check [FILE]n

Print or check %s (%d-bit) checksums.n

With no FILE, or when FILE is -, read standard input.n

"),

program_name, program_name,

DIGEST_TYPE_STRING (algorithm),

DIGEST_BITS (algorithm));

printf (_("

n

-b, --binary read files in binary mode (default on DOS/Windows)n

-c, --check check %s sums against given listn

-t, --text read files in text mode (default)n

n

"),

DIGEST_TYPE_STRING (algorithm));

fputs (_("

The following two options are useful only when verifying checksums:n

--status don't output anything, status code shows successn

-w, --warn warn about improperly formated checksum linesn

n

"), stdout);

fputs (HELP_OPTION_DESCRIPTION, stdout);

fputs (VERSION_OPTION_DESCRIPTION, stdout);

printf (_("

n

The sums are computed as described in %s. When checking, the inputn

should be a former output of this program. The default mode is to printn

a line with checksum, a character indicating type (`*' for binary, ` ' forn

text), and name for each FILE.n"),

(algorithm == ALG_MD5 ? "RFC 1321" : "FIPS-180-1"));

printf (_("nReport bugs to

java digestutils.md5hex_linux下md5sum和DigestUtils.md5Hex的关系 博客分类: java相关推荐

  1. java支持html5视频流技术Pseudostreaming – Roden的专栏 – CSDN博客

    文章目录[隐藏] java支持html5视频流技术Pseudostreaming 首页博客学院 下载论坛APP 问答商城活动VIP会员专题招聘ITeyeGitChat 图文课 写博客 消息 登录注册 ...

  2. vsphere通用配置_Mac环境下如何用Hexo+Github搭建个人博客

    一个爱折腾的人,总是忍不住去自己动手尝试新鲜事物.就拿写博客来说,虽然网上已经提供了很多博客平台,但是总有一些个性化的需要得不到满足.所以就抽空去网上找了下如何使用Hexo+Github 搭建自己博客 ...

  3. 基于SMB协议的共享文件读写 博客分类: Java

    基于SMB协议的共享文件读写 博客分类: Java 一.SMB协议 SMB协议是基于TCP-NETBIOS下的,一般端口使用为139,445. 服务器信息块(SMB)协议是一种IBM协议,用于在计算机 ...

  4. 自媒体形式下的个人设计(面向用户)—博客,QQ空间等个人主页的设计

    自媒体形式下的个人设计(面向用户)-博客,QQ空间等个人主页的设计 在当今的虚拟网络社会,每个人都能在这个Internet上找到个人的影子,作为网络社交的名片的个人主页,例如:QQ空间,个人博客.当然 ...

  5. java项目-第120期儿童成长博客记录系统-java毕业设计

    java项目-第120期儿童成长博客记录系统-java毕业设计 [源码请到资源专栏下载] Hi,大家好,今天分享的源码是<基于SpringBoot的儿童成长记录博客系统>. BabyLog ...

  6. 最近准备把安卓和java的知识再回顾一遍,顺便会写博客上!千变万化还都是源于基础,打扎实基础...

    最近准备把安卓和java的知识再回顾一遍,顺便会写博客上!千变万化还都是源于基础,打扎实基础,加油吧 距离去北京还有23天 转载于:https://www.cnblogs.com/AceIsSunsh ...

  7. CSDN博客 - 分类专栏:如何在一级专栏下建立二级专栏(子专栏)

    如何在一级专栏下建立二级专栏(子专栏) 博客专栏可以建立二级子专栏,但是不是点击一级专栏直接创建,根据官方提示是: 个人分类与专栏管理合并啦! 双击分类名称,即可编辑,输入 "#" ...

  8. 最值得收藏的java技术博客(Java篇)

    第一个:java_my_life 作者介绍:找不到原作者信息.大概做了翻阅全部是2012年的博客. 博客主要内容:主要内容是关于Java设计模式的一些讲解和学习笔记,在相信对学习设计模式的同学帮助很大 ...

  9. java 模拟登陆exe_Java简单模拟登陆和爬虫实例---博客园老牛大讲堂

    鉴于有人说讲的不清楚,我这里再详细补充一下:更新日期:2017-11-23 本片文章适合初学者,只简单说了一下爬虫怎么用,和一个简单的小实例.不适合你的就可以不看了.----博客园老牛大讲堂 1.什么 ...

  10. 基于SpringBoot+Vue开发的前后端分离博客项目-Java后端接口开发

    文章目录 1. 前言 2. 新建Springboot项目 3. 整合mybatis plus 第一步:导依赖 第二步:写配置文件 第三步:mapper扫描+分页插件 第四步:代码生成配置 第五步:执行 ...

最新文章

  1. 【天命奇御】成就进度62/71的通关攻略(1·开篇前言)
  2. Linux内存初始化(一)
  3. 第六周项目一-分数类的雏形(2)
  4. 手持GPS坐标系统的转换与应用
  5. nginx后端节点健康检查
  6. TRY NOT TO SAY SO MUCH!
  7. 落纱机器人_「聚焦」青岛艾菲特智能落纱机器人—智能制造,为您省工
  8. 进入前端开发这个领域 ,请问如何进行系统的学习?
  9. powershell 开发入门_详谈Ubuntu PowerShell(小白入门必看教程)
  10. Java Servlet request
  11. yolov1-v5学习笔记及源码解读
  12. java dos攻击_一种高级的DoS攻击-Hash碰撞攻击
  13. Android-SEAndroid权限问题指南
  14. Mybatis 官网地址
  15. 《追寻生命的意义》摘抄
  16. RK3568平台开发系列讲解(安卓篇)WakeLock分析
  17. 港科喜讯 | 36名香港科大教授获得表彰!
  18. 不出国,雅思也有大用。来看这篇IELTS雅思考试超详细扫盲贴
  19. 矿大G毕业生的礼物(贪心)
  20. php 加密解密方法,php加密方法与解密方法

热门文章

  1. QQ连连看单机版辅助制作全流程
  2. 单词发音,为语音识别准备素材
  3. 如何在eclipse中使用Struts2框架
  4. SOCKS5 协议原理详解与应用场景分析
  5. CC++期末课程设计——产品管理系统(源代码+详细注释)
  6. cpu单核性能测试软件,CPU常用跑分软件 你知道那些?
  7. 2019-9-2-贡献自己的服务器搭建tor中转
  8. CentOS 搭建pure-ftpd
  9. java action例子_实例——创建ActionForm Bean
  10. instsrv.exe srvany.exe 实现不登陆桌面启动