トップ 履歴 一覧 カテゴリ ソース 検索 ヘルプ RSS ログイン

WinCmd/CertUtil

INDEX

証明書サービス用コマンドラインツール。

CertUtil

https://learn.microsoft.com/ja-jp/windows-server/administration/windows-commands/certutil

証明書関連のツールだが、Base64 のデコード/エンコード、HEXダンプ、ハッシュ値の表示などの機能もある。

 -hashfile : ファイルのハッシュ値の表示

CertUtil [options] -hashfile InFile [HashAlgorithm]

ハッシュ値を求めるファイルパスを指定する。また、求めるハッシュ アルゴリズムも指定する。指定できるアルゴリズムは、 MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512 で、未指定は SHA1 でとなる。

C:\>CertUtil -hashfile C:\Windows\notepad.exe
SHA1 ハッシュ (対象 C:\Windows\notepad.exe):
66b6158b28cc2b970e454b6a8cf1824dd99e4029
CertUtil: -hashfile コマンドは正常に完了しました。

C:\>CertUtil -hashfile C:\Windows\notepad.exe MD5
MD5 ハッシュ (対象 C:\Windows\notepad.exe):
1c1760ed4d19cdbecb2398216922628b
CertUtil: -hashfile コマンドは正常に完了しました。

C:\>CertUtil -hashfile C:\Windows\notepad.exe SHA256
SHA256 ハッシュ (対象 C:\Windows\notepad.exe):
d66458a3eb1b68715b552b3af32a9d2e889bbf8ac0c23c1afa8d0982023d1ce2
CertUtil: -hashfile コマンドは正常に完了しました。

C:\>CertUtil -hashfile C:\Windows\notepad.exe SHA512
SHA512 ハッシュ (対象 C:\Windows\notepad.exe):
f058eda0c65e59105a7c794721697782f1e1db759c69a11dab09ca454aa89767addcc8ecefa54995527bc2cae983e44c9ed42b0973fdb47435b31428150b96db
CertUtil: -hashfile コマンドは正常に完了しました。

C:\>

 -encodehex : HEXダンプ

CertUtil [options] -encodehex InFile OutFile [type]

入力ファイルを16進数テキストに変換して、テキストの出力ファイルを作成する。オプションに -f を指定すると、すでに出力ファイルがあっても上書きする。

作成するフォーマット形式 type は、CRYPT_STRING_* の数値を指定する。

C:\>CertUtil -f -encodehex C:\Windows\notepad.exe notepad_hex.txt
入力長 = 211968
出力長 = 989504
CertUtil: -encodehex コマンドは正常に完了しました。

C:\>type notepad_hex.txt
0000    4d 5a 90 00 03 00 00 00  04 00 00 00 ff ff 00 00   MZ..............
0010    b8 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00   ........@.......

 -decodehex : HEXダンプ

CertUtil [options] -decodehex InFile OutFile [type]

16進数テキストの入力ファイルを変換して、バイナリデータの出力ファイルを作成する。オプションに -f を指定すると、すでに出力ファイルがあっても上書きする。フォーマット形式 type は、CRYPT_STRING_* の数値を指定する。

C:\>CertUtil -f -decodehex notepad_hex.txt notepad.bin
入力長 = 989504
出力長 = 211968
CertUtil: -decodehex コマンドは正常に完了しました。

C:\>FC /B C:\Windows\notepad.exe notepad.bin
ファイル C:\WINDOWS\notepad.exe と NOTEPAD.BIN を比較しています
FC: 相違点は検出されませんでした


C:\>

 -encode : Base64 エンコード

CertUtil [options] -encode InFile OutFile

入力ファイルを Base64 エンコードして、出力ファイルを作成する。オプションに -f を指定すると、すでに出力ファイルがあっても上書きする。

ちなみに、証明書用のツールなのでPEM形式のファイルになる。

C:\>CertUtil -f -encode C:\Windows\notepad.exe notepad_base64.txt
入力長 = 211968
出力長 = 291512
CertUtil: -encode コマンドは正常に完了しました。

C:\Temp>type notepad_base64.txt
-----BEGIN CERTIFICATE-----
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA+AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v
  :中略
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-----END CERTIFICATE-----

C:\>

 -decode : Base64 デコード

CertUtil [options] -decode InFile OutFile

入力ファイルを Base64 デコードして、バイナリの出力ファイルを作成する。オプションに -f を指定すると、すでに出力ファイルがあっても上書きする。

C:\>CertUtil -f -decode notepad_base64.txt notepad.bin
入力長 = 291512
出力長 = 211968
CertUtil: -decode コマンドは正常に完了しました。

C:\Temp>FC /B C:\Windows\notepad.exe notepad.bin
ファイル C:\WINDOWS\notepad.exe と NOTEPAD.BIN を比較しています
FC: 相違点は検出されませんでした


C:\>

 -error : エラーコードのメッセージの表示

CertUtil [options] -error ErrorCode

ErrorCode は、Win32のエラーコード もしくは HRESULTの値 を指定する。

C:\>CertUtil -error 0
0x0 (WIN32: 0) -- 0 (0)
エラー メッセージ テキスト: この操作を正しく終了しました。
CertUtil: -error コマンドは正常に完了しました。

C:\>CertUtil -error 53
0x35 (WIN32: 53 ERROR_BAD_NETPATH) -- 53 (53)
エラー メッセージ テキスト: ネットワーク パスが見つかりません。
CertUtil: -error コマンドは正常に完了しました。

C:\>
C:\>CertUtil -error 0x00000000
0x0 (WIN32: 0) -- 0 (0)
エラー メッセージ テキスト: この操作を正しく終了しました。
CertUtil: -error コマンドは正常に完了しました。

C:\>CertUtil -error 0x80004004
0x80004004 (-2147467260 E_ABORT) -- 2147500036 (-2147467260)
エラー メッセージ テキスト: 操作は中断されました
CertUtil: -error コマンドは正常に完了しました。

C:\>CertUtil -error 0x80004005
0x80004005 (-2147467259 E_FAIL) -- 2147500037 (-2147467259)
エラー メッセージ テキスト: エラーを特定できません
CertUtil: -error コマンドは正常に完了しました。

C:\>

最終更新時間:2023年06月16日 18時59分36秒 指摘や意見などあればSandBoxのBBSへ。