class RbNaCl::Boxes::Curve25519XSalsa20Poly1305
def open(nonce, ciphertext)
-
(String)
- The decrypted message (BINARY encoded)
Raises:
-
(RbNaCl::CryptoError)
- If the ciphertext cannot be authenticated. -
(RbNaCl::LengthError)
- If the nonce is not valid
Parameters:
-
ciphertext
(String
) -- The message to be decrypted. -
nonce
(String
) -- A 24-byte string containing the nonce.
def open(nonce, ciphertext) Util.check_length(nonce, nonce_bytes, "Nonce") ct = Util.prepend_zeros(BOXZEROBYTES, ciphertext) message = Util.zeros(ct.bytesize) success = self.class.box_curve25519xsalsa20poly1305_open_afternm(message, ct, ct.bytesize, nonce, beforenm) raise CryptoError, "Decryption failed. Ciphertext failed verification." unless success Util.remove_zeros(ZEROBYTES, message) end