pub struct EncryptedPayload {
pub ciphertext: Vec<u8>,
pub salt: [u8; 16],
pub nonce: [u8; 12],
}Expand description
An encrypted payload: the ciphertext plus the salt and nonce needed to decrypt it (§1.2 — a represented state, not a bag of bytes).
The salt and nonce are generated fresh per encryption call (§1.3.1 — GCM nonce reuse is catastrophic), so two encryptions of the same plaintext with the same password yield different payloads.
Fields§
§ciphertext: Vec<u8>The AES-256-GCM ciphertext (includes the GCM authentication tag).
salt: [u8; 16]The PBKDF2 salt — 16 random bytes, unique per encryption.
nonce: [u8; 12]The GCM nonce — 12 random bytes, unique per encryption.
Implementations§
Source§impl EncryptedPayload
impl EncryptedPayload
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Encode the payload as base64 of salt || nonce || ciphertext — a single
self-contained string the browser fetch monkeypatch can decode and decrypt.
The format is: first 16 bytes = salt, next 12 bytes = nonce, rest =
ciphertext (including GCM tag). This is NOT valid JSON, so
serde_json::from_str fails on it (the JSON-bypass guard).
Sourcepub fn from_base64(s: &str) -> Result<Self, CryptoError>
pub fn from_base64(s: &str) -> Result<Self, CryptoError>
Decode a base64 payload (salt || nonce || ciphertext) back into an
EncryptedPayload.
Trait Implementations§
Source§impl Clone for EncryptedPayload
impl Clone for EncryptedPayload
Source§fn clone(&self) -> EncryptedPayload
fn clone(&self) -> EncryptedPayload
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more