Skip to main content

encrypted_cookie

Function encrypted_cookie 

Source
pub fn encrypted_cookie(value: &str, key: &[u8]) -> String
Available on crate feature crypto only.
Expand description

Encrypts value with AES-256-GCM. key may be any length — it’s hashed with SHA-256 first to produce the required 256-bit key, the same convenience signed_cookie’s HMAC secret already offers. A fresh random 96-bit nonce is generated on every call. Returns "<hex-nonce>.<hex-ciphertext-and-tag>" — store the result directly as a cookie value.

Unlike signed_cookie, the value is not readable by the client at all, not just tamper-evident.