Module: Google::ShaUtil

Extended by:
ShaUtil
Included in:
ShaUtil
Defined in:
lib/google/sha_util.rb

Constant Summary collapse

SHA256 =
OpenSSL::Digest::SHA256.new

Instance Method Summary collapse

Instance Method Details

#sha256_digest(str) ⇒ Object



16
17
18
# File 'lib/google/sha_util.rb', line 16

def sha256_digest str
  SHA256.digest(str)
end

#sha256_hex(str, prefix = nil) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/google/sha_util.rb', line 7

def sha256_hex str, prefix = nil
  hash = sha256_digest(str).unpack("H64").first
  if prefix
    hash.first(prefix)  # first 'prefix' chars
  else
    hash
  end
end