Skip to main content

laravel_rust_encryption/
lib.rs

1//! A Rust port of Laravel's `Illuminate\Encryption\Encrypter`, wire-compatible with Laravel
2//! 10 through 13.
3//!
4//! Decrypt in Rust what Laravel encrypted with `Crypt` / `Encrypter`, and produce payloads
5//! Laravel can decrypt, using the same key.
6//!
7//! ```
8//! use laravel_rust_encryption::{Cipher, Encrypter};
9//!
10//! // A Laravel `APP_KEY`; use `std::env::var("APP_KEY")` in an application.
11//! let app_key = "base64:KysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKys=";
12//! let enc = Encrypter::from_app_key(app_key, Cipher::Aes256Cbc)?;
13//!
14//! // Crypt::encryptString / Crypt::decryptString
15//! let payload = enc.encrypt_string("hello")?;
16//! assert_eq!(enc.decrypt_string(&payload)?, "hello");
17//! # Ok::<(), laravel_rust_encryption::Error>(())
18//! ```
19//!
20//! The payload is `base64(json{"iv", "value", "mac", "tag"})`:
21//!
22//! - **AES-CBC**: random 16-byte IV, PKCS#7 padding, `mac` = lower-case hex
23//!   `HMAC-SHA256(base64(iv) + base64(value), key)`, `tag` empty.
24//! - **AES-GCM**: random 12-byte IV, the 16-byte tag in `tag`, `mac` empty.
25
26#![forbid(unsafe_code)]
27#![warn(missing_docs)]
28
29mod encrypter;
30mod error;
31mod php;
32
33pub use encrypter::{parse_key, Cipher, Encrypter};
34pub use error::{Error, Result};
35pub use php::{Key, Value};