class Sodium::SecretBox
- Sodium::SecretBox
- Sodium::Key
- Reference
- Object
Overview
https://libsodium.gitbook.io/doc/secret-key_cryptography
box = Sodium::SecretBox.new
message = "foobar"
encrypted, nonce = box.encrypt message
# On the other side.
box = Sodium::SecretBox.new key
message = key.decrypt encrypted, nonce: nonce
Defined in:
sodium/secret_box.crConstant Summary
-
KEY_SIZE =
LibSodium.crypto_secretbox_keybytes.to_i
-
MAC_SIZE =
LibSodium.crypto_secretbox_macbytes.to_i
-
NONCE_SIZE =
LibSodium.crypto_secretbox_noncebytes.to_i
Constructors
-
.new(key : SecureBuffer)
Use an existing SecureBuffer.
-
.new(bytes : Bytes, erase = false)
Copy bytes to a new SecureBuffer
-
.new
Generate a new random key held in a SecureBuffer.
Instance Method Summary
-
#decrypt(src, dst : Bytes? = nil, *, nonce : Nonce) : Bytes
Returns decrypted message.
-
#decrypt_string(src, dst : Bytes? = nil, *, nonce : Nonce) : String
Returns decrypted message as a
String
. -
#encrypt(src, dst : Bytes? = nil, *, nonce : Nonce? = nil)
Encrypts data and returns {ciphertext, nonce}
-
#key : SecureBuffer
Encryption key
-
#to_slice : Bytes
Returns key
Instance methods inherited from class Sodium::Key
to_slice : Bytes
to_slice
Instance methods inherited from module Sodium::Wipe
close
close,
finalize
finalize
Constructor Detail
def self.new(bytes : Bytes, erase = false)
#
Copy bytes to a new SecureBuffer
Optionally erases bytes after copying if erase is set.
Instance Method Detail
Returns decrypted message.
Optionally supply a destination buffer.
Returns decrypted message as a String
.
Optionally supply a destination buffer.
Encrypts data and returns {ciphertext, nonce}
Optionally supply a destination buffer.