doc @ http://www.ruby-doc.org/stdlib-1.9.3/libdoc/digest/rdoc/Digest/SHA2.html显示:
Digest::SHA256.new.digest_length * 8
#=> 512
Digest::SHA384.new.digest_length * 8
#=> 1024
Digest::SHA512.new.digest_length * 8
#=> 1024
这是2.1.3
中的输出:
Digest::SHA256.new.digest_length * 8
#=> 256
Digest::SHA384.new.digest_length * 8
#=> 384
Digest::SHA512.new.digest_length * 8
#=> 512
为什么我的块长度输出与Ruby文档不同?
答案 0 :(得分:0)
似乎文档中有拼写错误,看,
block_length → Integer
Returns the block length of the digest in bytes.
Digest::SHA256.new.digest_length * 8
# => 512
Digest::SHA384.new.digest_length * 8
# => 1024
Digest::SHA512.new.digest_length * 8
# => 1024
digest_length → Integer
Returns the length of the hash value of the digest in bytes.
Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512
两者都在示例中使用digest_length
。
但它应该是,
block_length → Integer
Returns the block length of the digest in bytes.
Digest::SHA256.new.block_length * 8
# => 512
Digest::SHA384.new.block_length * 8
# => 1024
Digest::SHA512.new.block_length * 8
# => 1024
digest_length → Integer
Returns the length of the hash value of the digest in bytes.
Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512
答案 1 :(得分:0)
This has been fixed in the 2.0.0 documentation(commit)
方法Digest::SHA2#block_length
的Ruby 1.9.3文档中似乎存在错误,因为它们在示例中使用digest_length
方法而不是block_length
。
使用digest_block
实际获得显示的值512
,1024
和1024
:
Digest::SHA256.new.block_length * 8
# => 512
Digest::SHA384.new.block_length * 8
# => 1024
Digest::SHA512.new.block_length * 8
# => 1024