Module: Kutils::CryptoUtils

Defined in:
lib/utils/crypto_utils.rb

Overview

CryptoUtils provides common hash and encoding utilities.

Class Method Summary collapse

Class Method Details

.base64_encode(str) ⇒ String

Base64 encode string

Parameters:

  • str (String)

Returns:

  • (String)


32
33
34
# File 'lib/utils/crypto_utils.rb', line 32

def self.base64_encode(str)
  Base64.strict_encode64(str)
end

.hmac_sha256(data, key) ⇒ String

Calculate HMAC-SHA256 hex digest

Parameters:

  • data (String)
  • key (String)

Returns:

  • (String)


25
26
27
# File 'lib/utils/crypto_utils.rb', line 25

def self.hmac_sha256(data, key)
  OpenSSL::HMAC.hexdigest('SHA256', key, data)
end

.md5(str) ⇒ String

Calculate MD5 hex digest

Parameters:

  • str (String)

Returns:

  • (String)


17
18
19
# File 'lib/utils/crypto_utils.rb', line 17

def self.md5(str)
  Digest::MD5.hexdigest(str)
end