method aead.unsealChaCha
Verifies and decrypts what sealChaCha produced; a wrong key or modified data is a CryptoError.
Example:
use std.crypto { aead, CryptoError }
use std.ser { bytesOf }
fn main() io, rand {
let key = bytesOf(&"0123456789abcdef0123456789abcdef")
let sealed = aead.sealChaCha(key, bytesOf(&"hi"), bytesOf(&"ctx-a"))!
match aead.unsealChaCha(key, sealed, bytesOf(&"ctx-b")) {
bytes _ => print("opened")
CryptoError _ => print("refused")
}
}Output
refused
pub(api) static fn unsealChaCha(key: bytes, sealed: bytes, aad: bytes = b"") -> bytes | CryptoErrorComplexity. O(n) in the size of the message.
Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
key | bytes |
sealed | bytes |
aad | bytes = b"" |
Returns
bytes
Errors
CryptoError@error- `CryptoError` for a wrong key, modified data or different associated data.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/crypto/crypto.oxl:525