Class: BlockChyp::CryptoUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_utils.rb

Overview

crypto and encoding utilities

Class Method Summary collapse

Class Method Details

.bin2hex(val) ⇒ Object



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

def self.bin2hex(val)
  val.each_byte.map { |b| b.to_s(16) }.join
end

.generate_nonceObject



9
10
11
# File 'lib/crypto_utils.rb', line 9

def self.generate_nonce
  bin2hex(SecureRandom.bytes(32))
end

.hex2bin(val) ⇒ Object



21
22
23
# File 'lib/crypto_utils.rb', line 21

def self.hex2bin(val)
  val.scan(/../).map { |x| x.hex.chr }.join
end

.timestampObject



13
14
15
# File 'lib/crypto_utils.rb', line 13

def self.timestamp
  Time.now.utc.to_datetime.rfc3339
end