Abstract base class for Authenticated Encryption with Additional Data
This construction encrypts a message, and computes an authentication tag for the encrypted message and some optional additional data
RbNaCl provides wrappers for both ChaCha20-Poly1305 AEAD implementations in libsodium: the original, and the IETF version.
Constant Summary collapseNumber of bytes in a valid key
0
Number of bytes in a valid nonce
0
The key bytes for the AEAD class.
The nonce bytes for the AEAD class.
The number bytes in the tag or authenticator from this AEAD class.
Decrypts and verifies an encrypted message with additional authenticated data.
Encrypts and authenticates a message with additional authenticated data.
Create a new AEAD using the IETF chacha20poly1305 construction.
The key bytes for the AEAD instance.
The nonce bytes for the AEAD instance.
The crypto primitive for this aead instance.
The number of bytes in the tag or authenticator for this AEAD instance.
Create a new AEAD using the IETF chacha20poly1305 construction
Sets up AEAD with a secret key for encrypting and decrypting messages.
32 33 34
# File 'lib/rbnacl/aead/base.rb', line 32 def initialize(key) @key = Util.check_string(key, key_bytes, "Secret key") endClass Method Details .key_bytes ⇒ Integer
The key bytes for the AEAD class
104 105 106
# File 'lib/rbnacl/aead/base.rb', line 104 def self.key_bytes self::KEYBYTES end.nonce_bytes ⇒ Integer
The nonce bytes for the AEAD class
90 91 92
# File 'lib/rbnacl/aead/base.rb', line 90 def self.nonce_bytes self::NPUBBYTES end.tag_bytes ⇒ Integer
The number bytes in the tag or authenticator from this AEAD class
118 119 120
# File 'lib/rbnacl/aead/base.rb', line 118 def self.tag_bytes self::ABYTES endInstance Method Details #decrypt(nonce, ciphertext, additional_data) ⇒ String
Decrypts and verifies an encrypted message with additional authenticated data
68 69 70 71 72 73 74 75 76 77 78
# File 'lib/rbnacl/aead/base.rb', line 68 def decrypt(nonce, ciphertext, additional_data) Util.check_length(nonce, nonce_bytes, "Nonce") message_len = Util.zeros(1) message = Util.zeros(data_len(ciphertext) - tag_bytes) success = do_decrypt(message, message_len, nonce, ciphertext, additional_data) raise CryptoError, "Decryption failed. Ciphertext failed verification." unless success message end#encrypt(nonce, message, additional_data) ⇒ String
Encrypts and authenticates a message with additional authenticated data
46 47 48 49 50 51 52 53 54 55 56
# File 'lib/rbnacl/aead/base.rb', line 46 def encrypt(nonce, message, additional_data) Util.check_length(nonce, nonce_bytes, "Nonce") ciphertext_len = Util.zeros(1) ciphertext = Util.zeros(data_len(message) + tag_bytes) success = do_encrypt(ciphertext, ciphertext_len, nonce, message, additional_data) raise CryptoError, "Encryption failed" unless success ciphertext end#key_bytes ⇒ Integer
The key bytes for the AEAD instance
111 112 113
# File 'lib/rbnacl/aead/base.rb', line 111 def key_bytes self.class.key_bytes end#nonce_bytes ⇒ Integer
The nonce bytes for the AEAD instance
97 98 99
# File 'lib/rbnacl/aead/base.rb', line 97 def nonce_bytes self.class.nonce_bytes end#primitive ⇒ Symbol
The crypto primitive for this aead instance
83 84 85
# File 'lib/rbnacl/aead/base.rb', line 83 def primitive self.class.primitive end#tag_bytes ⇒ Integer
The number of bytes in the tag or authenticator for this AEAD instance
125 126 127
# File 'lib/rbnacl/aead/base.rb', line 125 def tag_bytes self.class.tag_bytes end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4