2

http://ruby.about.com/od/advancedruby/ss/Cryptographic-Hashes-In-Ruby.htmからこのコードを入力すると

#!/usr/bin/env ruby
require 'digest'

password = "A user's password"
hash = Digest::SHA1.hexdigest(password)
puts hash

# This will produce the hash
# 62018390552aaba3d344e3b43bfa14e49e535dfc

私は彼らが私がそうすると言った答えを得る。

しかし、このシェルコマンドを入力すると

echo "A user's password" | openssl dgst -sha1 -hex

95f33732bafc1744bf24e0cae4e014ab2e5f1580を取得します

なんでお願い?

4

1 に答える 1

11

コマンドラインの例には、Ruby文字列で指定されていない改行が含まれています。-n使用してみてくださいecho。改行をスキップします。

$ echo "A user's password" | openssl dgst -sha1 -hex
95f33732bafc1744bf24e0cae4e014ab2e5f1580
$ echo -n "A user's password" | openssl dgst -sha1 -hex
62018390552aaba3d344e3b43bfa14e49e535dfc
于 2012-12-20T04:03:04.613 に答える