php -r 'echo sha1("engineering");' echo -n 'engineering' | perl -lne 'use Digest::SHA1 qw(sha1_hex); print sha1_hex("$_")' perl -le 'use Digest::SHA1 qw(sha1_hex); print sha1_hex("engineering");' echo -n 'engineering' | openssl dgst -sha1 --- 72917ef6c1d976fb7d5e3e52394a829d441ed3cd
php -r 'echo md5("engineering");' echo -n 'engineering' | perl -lne 'use Digest::MD5 qw(md5_hex); print md5_hex("$_")' perl -le 'use Digest::MD5 qw(md5_hex); print md5_hex("engineering");' echo -n 'engineering'| openssl dgst -md5 --- 5d554bc5f3d2cd182cdd0952b1fb87ca
$ echo engineering |base64 ZW5naW5lZXJpbmcK $ echo ZW5naW5lZXJpbmcK |base64 -d engineering
$ echo http://tomocha.net/ | base64 aHR0cDovL3RvbW9jaGEubmV0Lwo= $ echo aHR0cDovL3RvbW9jaGEubmV0Lwo= |base64 -d http://tomocha.net/
echo -n 'engineering' | perl -lne 'print unpack("H*", $_)' perl -le 'print unpack("H*","engineering");' --- 656e67696e656572696e67
逆
echo '656e67696e656572696e67' | perl -lne 'print pack("H*", $_)' perl -le 'print pack("H*", "656e67696e656572696e67")'
その他
openssl には次のアルゴリズムが対応している。
options are -c to output the digest with separating colons -d to output debug info -hex output as hex dump -binary output in binary form -sign file sign digest using private key in file -verify file verify a signature using public key in file -prverify file verify a signature using private key in file -keyform arg key file format (PEM or ENGINE) -signature file signature to verify -binary output in binary form -engine e use engine e, possibly a hardware device. -md5 to use the md5 message digest algorithm (default) -md4 to use the md4 message digest algorithm -md2 to use the md2 message digest algorithm -sha1 to use the sha1 message digest algorithm -sha to use the sha message digest algorithm -sha224 to use the sha224 message digest algorithm -sha256 to use the sha256 message digest algorithm -sha384 to use the sha384 message digest algorithm -sha512 to use the sha512 message digest algorithm -mdc2 to use the mdc2 message digest algorithm -ripemd160 to use the ripemd160 message digest algorithm
使い方は簡単。
# echo -n 'engineering' | openssl dgst <algorithm>