Class: Cryptor::Ciphers::XSalsa20Poly1305

Inherits:
Cryptor::Cipher show all
Defined in:
lib/cryptor/ciphers/xsalsa20poly1305.rb

Overview

XSalsa20+Poly1305 authenticated stream cipher

Constant Summary

Constants inherited from Cryptor::Cipher

Cryptor::Cipher::REGISTRY

Instance Attribute Summary

Attributes inherited from Cryptor::Cipher

#algorithm, #key_bytes

Instance Method Summary collapse

Methods inherited from Cryptor::Cipher

[], #initialize, #random_key, register

Constructor Details

This class inherits a constructor from Cryptor::Cipher

Instance Method Details

#decrypt(key, ciphertext) ⇒ Object



15
16
17
18
19
# File 'lib/cryptor/ciphers/xsalsa20poly1305.rb', line 15

def decrypt(key, ciphertext)
  box(key).decrypt(ciphertext)
rescue RbNaCl::CryptoError => ex
  raise CorruptedMessageError, ex.to_s
end

#encrypt(key, plaintext) ⇒ Object



11
12
13
# File 'lib/cryptor/ciphers/xsalsa20poly1305.rb', line 11

def encrypt(key, plaintext)
  box(key).encrypt(plaintext)
end