Class: Secretbox

Inherits:
AbstractSymmetricCrypt show all
Defined in:
lib/ruby-common/v5/Secretbox.rb

Constant Summary collapse

METHOD =
0x0101

Instance Method Summary collapse

Methods inherited from AbstractSymmetricCrypt

#parse

Instance Method Details

#decrypt_with_key(payload, key) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ruby-common/v5/Secretbox.rb', line 6

def decrypt_with_key(payload, key)
  nonce_bytes = 24
  parse = parse(payload, { iv: nonce_bytes })
  secret_box = RbNaCl::SecretBox.new(key)
  return secret_box.decrypt(parse.byte_buffer_map[:iv], parse.data)
rescue RbNaCl::CryptoError
  raise 'Decryption failed'
end