Module: WebriskHash::Hash
Instance Method Summary collapse
-
#truncated_sha256_prefix(str, bits) ⇒ String
Compute SHA256 hash and return truncated prefix.
Instance Method Details
#truncated_sha256_prefix(str, bits) ⇒ String
Compute SHA256 hash and return truncated prefix
For Web Risk, a hash prefix consists of the most significant 4-32 bytes of a SHA256 hash (32 to 256 bits)
27 28 29 30 31 |
# File 'lib/webrisk_hash/hash.rb', line 27 def truncated_sha256_prefix(str, bits) len = bits / 8 digest = ::Digest::SHA256.digest(str) digest.byteslice(0, len) end |