data aead
Authenticated encryption with a 32-byte key. seal returns nonce(12) || ciphertext || tag(16) with a fresh random
nonce; unseal verifies and decrypts. The associated data is authenticated but not encrypted and must be the same for
both calls. Random 96-bit nonces are safe for about 2^32 messages per key.
Example:
use std.crypto { aead }
use std.ser { bytesOf, textOf }
fn main() io, rand {
let key = bytesOf(&"0123456789abcdef0123456789abcdef")
let sealed = aead.seal(key, bytesOf(&"top secret"), bytesOf(&"user-7"))!
print(textOf(&aead.unseal(key, sealed, bytesOf(&"user-7"))!)!)
}Вывод
top secret
pub(api) data aeadПотокобезопасность. pure functions apart from the random nonce; safe from any task.
С версии. 1.0.0-beta
Методы
seal | (key: bytes, plain: bytes, aad: bytes) -> bytes | CryptoError randAES-256-GCM. |
unseal | (key: bytes, sealed: bytes, aad: bytes) -> bytes | CryptoErrorVerifies and decrypts; a wrong key or modified data is a CryptoError. |
sealChaCha | (key: bytes, plain: bytes, aad: bytes) -> bytes | CryptoError randChaCha20-Poly1305. |
unsealChaCha | (key: bytes, sealed: bytes, aad: bytes) -> bytes | CryptoErrorVerifies and decrypts what sealChaCha produced; a wrong key or modified data is a CryptoError. |
Определено в: std/crypto/crypto.oxl:433