Windows下CertUtil校验和编码文件
前言
CertUtil.exe是一个命令行程序,作为证书服务的一部分安装。可以使用CertUtil.exe转储和显示证书颁发机构(CA)配置信息、配置证书服务、备份和恢复CA组件,以及验证证书、密钥对和证书链。如果certutil在没有附加参数的证书颁发机构上运行,它将显示当前的证书颁发机构配置。如果certutil在非认证中心上运行,则该命令默认运行certutil [-dump]命令。
但是我只用了计算文件hash,以及编码解码文件功能,对我来说在Windows上不用安装额外软件就能实现这些功能很方便。
CertUtil计算文件hash
在Windows的cmd下执行CertUtil -hashfile -?会出现帮助文档,根据Hash algorithms: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512可以得到常用计算文件hash方法,md5和sha1比较常用。
Usage:
CertUtil [Options] -hashfile InFile [HashAlgorithm]
Generate and display cryptographic hash over a file
Options:
-Unicode -- Write redirected output in Unicode
-gmt -- Display times as GMT
-seconds -- Display times with seconds and milliseconds
-v -- Verbose operation
-privatekey -- Display password and private key data
-pin PIN -- Smart Card PIN
-sid WELL_KNOWN_SID_TYPE -- Numeric SID
22 -- Local System
23 -- Local Service
24 -- Network Service
Hash algorithms: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512
CertUtil -? -- Display a verb list (command list)
CertUtil -hashfile -? -- Display help text for the "hashfile" verb
CertUtil -v -? -- Display all help text for all verbs
计算MD2
CertUtil -hashfile test.txt MD2
MD2 hash of test.txt:
5892bec299b1bae578d5aff607f6eb61
CertUtil: -hashfile command completed successfully.
计算MD4
CertUtil -hashfile test.txt MD4
MD4 hash of test.txt:
a9c5d7b55b8173b39870bcdf919c71b7
CertUtil: -hashfile command completed successfully.
计算MD5
计算md5是比较常用的文件hash方式。
CertUtil -hashfile test.txt MD5
MD5 hash of test.txt:
02877f0b701bec19ed79911ccc7b20e3
CertUtil: -hashfile command completed successfully.
计算SHA1
CertUtil -hashfile test.txt SHA1
SHA1 hash of test.txt:
ae36676c8c6a617ed5d3a84b88c70cd5d9c362a5
CertUtil: -hashfile command completed successfully.
计算SHA256
CertUtil -hashfile test.txt SHA256
SHA256 hash of test.txt:
8df1da6d5c8b7a89ed3da070b652946d9db143fd22e98afdccf5d3d1ac3b29e9
CertUtil: -hashfile command completed successfully.
计算SHA384
CertUtil -hashfile test.txt SHA384
SHA384 hash of test.txt:
bc3cf094587ee7473fd460fac1f37db2d3fd7085cfe8d024cfb004d03824d555f46939bd8920a4db32d9e178da064560
CertUtil: -hashfile command completed successfully.
计算SHA512
CertUtil -hashfile test.txt SHA512
SHA512 hash of test.txt:
3b338d0a80a81f95cb8a654c2bcd9ec6385ee9da785708f8e5bb5eba37934d4c2b745faa823f3598fb56b32a32a833defdce3c195f7e4e3a1fa3b3b69f166969
CertUtil: -hashfile command completed successfully.
文件base64编码
在Windows的cmd执行CertUtil -encode -?可以查看编码文件为base64格式文件。
Usage:
CertUtil [Options] -encode InFile OutFile
Encode file to Base64
Options:
-f -- Force overwrite
-Unicode -- Write redirected output in Unicode
-UnicodeText -- Write output file in Unicode
-gmt -- Display times as GMT
-seconds -- Display times with seconds and milliseconds
-v -- Verbose operation
-privatekey -- Display password and private key data
-pin PIN -- Smart Card PIN
-sid WELL_KNOWN_SID_TYPE -- Numeric SID
22 -- Local System
23 -- Local Service
24 -- Network Service
CertUtil -? -- Display a verb list (command list)
CertUtil -encode -? -- Display help text for the "encode" verb
CertUtil -v -? -- Display all help text for all verbs
下面是对一个文件进行base64编码。结果文件首行和末行会有特殊标记。
CertUtil -encode test.txt test.txt.out
Input Length = 8
Output Length = 70
CertUtil: -encode command completed successfully.
cat test.txt
test
cat test.txt.out
-----BEGIN CERTIFICATE-----
dGVzdCAgDQo=
-----END CERTIFICATE-----
文件base64解码
在Windows的cmd执行CertUtil -decode -?可以查看解码base64格式文件。
Usage:
CertUtil [Options] -decode InFile OutFile
Decode Base64-encoded file
Options:
-f -- Force overwrite
-Unicode -- Write redirected output in Unicode
-gmt -- Display times as GMT
-seconds -- Display times with seconds and milliseconds
-v -- Verbose operation
-privatekey -- Display password and private key data
-pin PIN -- Smart Card PIN
-sid WELL_KNOWN_SID_TYPE -- Numeric SID
22 -- Local System
23 -- Local Service
24 -- Network Service
CertUtil -? -- Display a verb list (command list)
CertUtil -decode -? -- Display help text for the "decode" verb
CertUtil -v -? -- Display all help text for all verbs
下面是对一个base64文件进行解码。
CertUtil -decode test.txt.out test.txt.de
Input Length = 70
Output Length = 8
CertUtil: -decode command completed successfully.
cat test.txt.out
-----BEGIN CERTIFICATE-----
dGVzdCAgDQo=
-----END CERTIFICATE-----
cat test.txt.de
test
文件hex编码
在Windows的cmd执行CertUtil -encodehex -?可以查看编码文件为hex格式文件。
Usage:
CertUtil [Options] -encodehex InFile OutFile [type]
Encode file in hexadecimal
Options:
-f -- Force overwrite
-Unicode -- Write redirected output in Unicode
-UnicodeText -- Write output file in Unicode
-gmt -- Display times as GMT
-seconds -- Display times with seconds and milliseconds
-v -- Verbose operation
-privatekey -- Display password and private key data
-pin PIN -- Smart Card PIN
-sid WELL_KNOWN_SID_TYPE -- Numeric SID
22 -- Local System
23 -- Local Service
24 -- Network Service
CertUtil -? -- Display a verb list (command list)
CertUtil -encodehex -? -- Display help text for the "encodehex" verb
CertUtil -v -? -- Display all help text for all verbs
下面是对一个文件进行hex编码。结果类似Linux下的xxd格式,展示了文件hex的值。
CertUtil -encodehex test.txt test.hex
Input Length = 23
Output Length = 139
CertUtil: -encodehex command completed successfully.
cat test.txt
test1
test2
test3
cat test.hex
0000 74 65 73 74 31 0d 0a 74 65 73 74 32 0d 0a 74 65 test1..test2..te
0010 73 74 33 0d 0a 0d 0a st3....
文件hex解码
在Windows的cmd执行CertUtil -decodehex -?可以查看解码hex格式文件。
Usage:
CertUtil [Options] -decodehex InFile OutFile [type]
Decode hexadecimal-encoded file
type -- numeric CRYPT_STRING_* encoding type
Options:
-f -- Force overwrite
-Unicode -- Write redirected output in Unicode
-gmt -- Display times as GMT
-seconds -- Display times with seconds and milliseconds
-v -- Verbose operation
-privatekey -- Display password and private key data
-pin PIN -- Smart Card PIN
-sid WELL_KNOWN_SID_TYPE -- Numeric SID
22 -- Local System
23 -- Local Service
24 -- Network Service
CertUtil -? -- Display a verb list (command list)
CertUtil -decodehex -? -- Display help text for the "decodehex" verb
CertUtil -v -? -- Display all help text for all verbs
下面是对一个hex文件进行解码。
CertUtil -decodehex test.hex test.hex.out
Input Length = 139
Output Length = 23
CertUtil: -decodehex command completed successfully.
cat test.hex
0000 74 65 73 74 31 0d 0a 74 65 73 74 32 0d 0a 74 65 test1..test2..te
0010 73 74 33 0d 0a 0d 0a st3....
cat test.hex.out
test1
test2
test3
结语
熟练使用这个命令,可以方便的在Windows电脑上校验文件,以及编码解码文件。特别是编码为hex格式文件,可以分析文件的二进制数据。我以前遇到过文件包含不可见字符导致代码编译报错,却找不到哪里错误,这时候分析文件的二进制数据一目了然了。
Windows下CertUtil校验和编码文件的更多相关文章
- 配置 .vimrc 解决 Vim / gVim 在中文 Windows 下的字符编码问题
转载自:-杨博的日志 - 网易博客 Vim / gVim 在中文 Windows 下的字符编码有两个问题: 默认没有编码检测功能 如果一个文件本身采用的字符集比 GBK 大(如 UTF-8.UTF-1 ...
- windows下右键新建md文件
windows下右键新建md文件 打开注册表 win键+R打开运行对话框, 输入regedit, 打开注册表编辑器. 修改注册表 在磁盘的任意位置新建一个文件, 后缀名为reg, 并写入一下内容 [H ...
- windows下编辑过的文件在Linux下用vi打开行尾会多出一个^M符号
一般情况下,windows下编辑过的文件在Linux下用vi打开行尾会多出一个^M符号,如下图: 这是因为Windows等操作系统用的文本换行符和UNIX/Linux操作系统用的不同,Windows系 ...
- windows下自动删除过期文件的脚本
windows下自动删除过期文件的脚本 前言: 比如日志文件每天都产生,时间长了就会有很大的一堆垃圾.整理一下 定时删除文件的方法. 正文: Windows: 定时删除tomcat日志和缓存.可以保留 ...
- Python Windows下打包成exe文件
Python Windows 下打包成exe文件,使用PyInstaller 软件环境: 1.OS:Win10 64 位 2.Python 3.7 3.安装PyInstaller 先检查是否已安装Py ...
- windows下快速修改host文件
windows下快速修改host文件 win+r 输入 notepad c:\Windows\System32\drivers\etc\hosts
- 【Linux】windows下编写的脚本文件,放到Linux中无法识别格式
注意:我启动的时候遇到脚本错误 » sh startup.sh -m standalone tanghuang@bogon : command not found : command not foun ...
- windows下安装phpcms html/ 文件夹不可写的一种错误以及解决方法
朋友安装phpcms时遇到奇葩问题,环境搭建在windows7中,竟然出现 html/ 和 phpsso_server/caches/文件夹不可写问题(如图) 在windows下出现这种权限的问题真不 ...
- windows下consul利用json文件注册服务
windows下,以开发模式启动consul命令 consul agent -dev -config-dir=D:\tools\consul 人工注册服务,新建一个json文件 ,放到D:\tools ...
随机推荐
- Html中让输入框input和紧接在后的按钮button在垂直方向上对齐
<table border="0px" width="360px"> <tr><td colspan="10" ...
- 为什么ping不通google.com
前言 为什么在ping不通Google的时候,我们却可以web直接访问Google (已开启SSR 翻 墙) SSR访问Google 因为GFW的限制导致国内无法直接访问谷歌,那么SSR为什么能绕过限 ...
- IDEA编写JavaWeb出现乱码,成功解决!
使用IDEA写JavaWeb项目时,总会出现编码出错等问题,比如下面这样,页面显示出来一大堆乱码,下面跟着我来操作一下,可以成功解决! 首先在IDEA安装目录下有一个:bin的文件夹,打开后找到如下两 ...
- 【漫话DevOps】What is DevOps?
最近几年"DevOps"这个关键词经常出现在项目开发当中,特别是随着微服务/容器/cloud在项目中的大范围应用,你不想知道都很难.作为一个伴随CI/CD到DevOps一路走来的工 ...
- Linux:less and Aix:more
在运维工作中,经常要查询应用日志,有Linux和Aix系统,个人感觉,Linux查询日志用less命令比较方便,Aix查询日志用more命令比较方便,在此总结一下两个命令的使用方法 AIX more命 ...
- Video.js + HLS 在production环境下webpack打包后出错的解决方案
Video.js是一个非常强大的视频播放库,能在微信下完美提供inline小窗口播放模式,但当涉及到hls格式视频播放时就比较麻烦,出现的数种现象都不好解决. 错误现象: 1. PC Chrome ...
- 关于java基础_方法的学习
方法: 方法就是把一堆需要反复执行的代码封装起来,如果项目需要调用这段代码时,直接调用方法名即可 方法相当于榨汁机, 材料:水果 产出物:果汁 参数(材料):进入方法的数据 返回值(产出物):就是方法 ...
- 骚操作:不重启 JVM,如何替换掉已经加载的类?
Java对象行为 java.lang.instrument.Instrumentation 直接操作字节码 BTrace Arthas 三生万物 在遥远的希艾斯星球爪哇国塞沃城中,两名年轻的程序员正在 ...
- 【转】Locust性能-零基础入门系列(2) -重写wait_time
在虚拟模拟的时候,可能对等待时间有更高的要求,比如假如有这么一个场景要求:某任务要求每被执行1次,那么下次的等待时间就1秒钟.这种情况,是可以实现的,这也就体现了Locust的灵活性.可编程性,很多比 ...
- JVM学习(九)volatile应用
一.初认volatile 首先学习volatile关键字时,我们先简单的了解一下它能干啥: 工作内存与主内存同步延迟现象导致的可见性问题: 可通过synchronized或volatile关键字解决, ...