Skip to main content

Crate laravel_rust_encryption

Crate laravel_rust_encryption 

Source
Expand description

A Rust port of Laravel’s Illuminate\Encryption\Encrypter, wire-compatible with Laravel 10 through 13.

Decrypt in Rust what Laravel encrypted with Crypt / Encrypter, and produce payloads Laravel can decrypt, using the same key.

use laravel_rust_encryption::{Cipher, Encrypter};

// A Laravel `APP_KEY`; use `std::env::var("APP_KEY")` in an application.
let app_key = "base64:KysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKys=";
let enc = Encrypter::from_app_key(app_key, Cipher::Aes256Cbc)?;

// Crypt::encryptString / Crypt::decryptString
let payload = enc.encrypt_string("hello")?;
assert_eq!(enc.decrypt_string(&payload)?, "hello");

The payload is base64(json{"iv", "value", "mac", "tag"}):

  • AES-CBC: random 16-byte IV, PKCS#7 padding, mac = lower-case hex HMAC-SHA256(base64(iv) + base64(value), key), tag empty.
  • AES-GCM: random 12-byte IV, the 16-byte tag in tag, mac empty.

Structs§

Encrypter
A Laravel-compatible encrypter: Rust’s Illuminate\Encryption\Encrypter.

Enums§

Cipher
A cipher supported by Laravel’s encrypter.
Error
Errors returned by Encrypter.
Key
A PHP array key.
Value
A PHP value, as produced by unserialize() or accepted by serialize().

Functions§

parse_key
Resolves a key string, as found in a Laravel .env file, to raw key bytes.

Type Aliases§

Result
Result type used throughout the crate.