std::crypto::encryptSymmetric encryption and decryption.
Encrypt and decrypt data using AES-256-GCM.
import std::crypto::encrypt;
fn main() {
let key = crypto.random_bytes(32);
let ciphertext = encrypt.seal(key, "hello world");
match encrypt.try_open(key, ciphertext) {
Ok(plaintext) => println(plaintext),
Err(err) => println(encrypt.error_message(err)),
}
}
error_messageReturn a human-readable message for a [CryptoError].
last_open_errorReturn the last try_open error observed on this thread.
sealEncrypt plaintext using AES-256-GCM with the given key.
Returns the ciphertext (nonce + encrypted data) as bytes.
try_openDecrypt ciphertext using AES-256-GCM with the given key.
Returns Err(CryptoError) when the key or ciphertext is invalid, AES-GCM
authentication fails, or the decrypted bytes are not valid UTF-8.
openDecrypt ciphertext using AES-256-GCM with the given key.
Panics on invalid input or authentication failure. Use try_open for
structured error handling of attacker-controlled ciphertext.
must_openDecrypt ciphertext and panic on failure.
Alias for open, provided for callers that prefer an explicit must-style
name at the call site.
CryptoErrorStructured errors returned by try_open.
NoneNo error was observed.
InvalidKeyThe key input was not a valid AES-256 key.
ShortCiphertextThe ciphertext was too short to contain a nonce and GCM tag.
AuthFailedAES-GCM authentication failed.
InvalidUtf8The decrypted plaintext was not valid UTF-8.
AllocationFailureNative string allocation failed.