Method: AEAD::Cipher#encrypt

Defined in:
lib/aead/cipher.rb

#encrypt(nonce, aad, plaintext) ⇒ String

Encrypts a plaintext using the current Cipher.

IMPORTANT: Do not ever encrypt data using the same nonce more than once given a particular secret key. Doing so will violate the security guarantees of the AEAD cipher.

Parameters:

  • nonce (String)

    a unique nonce, never before used with the current encryption key

  • aad (String, nil)

    arbitrary additional authentication data that must later be provided to decrypt the aead

  • plaintext (String)

    arbitrary plaintext

Returns:

  • (String)

    the generated AEAD



112
113
114
115
116
117
118
119
120
# File 'lib/aead/cipher.rb', line 112

def encrypt(nonce, aad, plaintext)
  _verify_nonce_bytesize(nonce, self.nonce_len)

  self._encrypt(
     _pad_nonce(nonce),
     aad,
     plaintext
  )
end