文字列からワンライナーでハッシュ値を求める
シェル上で、文字列からワンライナーでハッシュ値を求めるにはopensslやshasumなどを用いる方法があります。opensslを使うのであれば例えば以下のように実行します。
echo -n "KEYWORD" | openssl sha256
シェルスクリプトとして実行し、アルゴリズム毎のハッシュ値を求める場合は以下のように実行します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
実行例は以下です。
1 2 3 4 5 6 7 8 9 10 11 | |
参考¶
openssl¶
% openssl --help
help:
Standard commands
asn1parse ca ciphers cmp
cms configutl crl crl2pkcs7
dgst dhparam dsa dsaparam
ec ecparam enc engine
errstr fipsinstall gendsa genpkey
genrsa help info kdf
list mac nseq ocsp
passwd pkcs12 pkcs7 pkcs8
pkey pkeyparam pkeyutl prime
rand rehash req rsa
rsautl s_client s_server s_time
sess_id skeyutl smime speed
spkac srp storeutl ts
verify version x509
Message Digest commands (see the `dgst' command for more details)
blake2b512 blake2s256 md4 md5
mdc2 rmd160 sha1 sha224
sha256 sha3-224 sha3-256 sha3-384
sha3-512 sha384 sha512 sha512-224
sha512-256 shake128 shake256 sm3
Cipher commands (see the `enc' command for more details)
aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb
aes-256-cbc aes-256-ecb aria-128-cbc aria-128-cfb
aria-128-cfb1 aria-128-cfb8 aria-128-ctr aria-128-ecb
aria-128-ofb aria-192-cbc aria-192-cfb aria-192-cfb1
aria-192-cfb8 aria-192-ctr aria-192-ecb aria-192-ofb
aria-256-cbc aria-256-cfb aria-256-cfb1 aria-256-cfb8
aria-256-ctr aria-256-ecb aria-256-ofb base64
bf bf-cbc bf-cfb bf-ecb
bf-ofb camellia-128-cbc camellia-128-ecb camellia-192-cbc
camellia-192-ecb camellia-256-cbc camellia-256-ecb cast
cast-cbc cast5-cbc cast5-cfb cast5-ecb
cast5-ofb des des-cbc des-cfb
des-ecb des-ede des-ede-cbc des-ede-cfb
des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb
des-ede3-ofb des-ofb des3 desx
idea idea-cbc idea-cfb idea-ecb
idea-ofb rc2 rc2-40-cbc rc2-64-cbc
rc2-cbc rc2-cfb rc2-ecb rc2-ofb
rc4 rc4-40 seed seed-cbc
seed-cfb seed-ecb seed-ofb sm4-cbc
sm4-cfb sm4-ctr sm4-ecb sm4-ofb
shasum¶
% shasum --help
Usage: shasum [OPTION]... [FILE]...
Print or check SHA checksums.
With no FILE, or when FILE is -, read standard input.
-a, --algorithm 1 (default), 224, 256, 384, 512, 512224, 512256
-b, --binary read in binary mode
-c, --check read SHA sums from the FILEs and check them
--tag create a BSD-style checksum
-t, --text read in text mode (default)
-U, --UNIVERSAL read in Universal Newlines mode
produces same digest on Windows/Unix/Mac
-0, --01 read in BITS mode
ASCII '0' interpreted as 0-bit,
ASCII '1' interpreted as 1-bit,
all other characters ignored
The following five options are useful only when verifying checksums:
--ignore-missing don't fail or report status for missing files
-q, --quiet don't print OK for each successfully verified file
-s, --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
-h, --help display this help and exit
-v, --version output version information and exit
When verifying SHA-512/224 or SHA-512/256 checksums, indicate the
algorithm explicitly using the -a option, e.g.
shasum -a 512224 -c checksumfile
The sums are computed as described in FIPS PUB 180-4. 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 type
(`*' for binary, ` ' for text, `U' for UNIVERSAL, `^' for BITS),
and name for each FILE. The line starts with a `\' character if the
FILE name contains either newlines or backslashes, which are then
replaced by the two-character sequences `\n' and `\\' respectively.
Report shasum bugs to mshelor@cpan.org