switon / crypto
Encryption, decryption, and key handling utilities for Switon Framework
v1.0.0
2026-05-09 23:36 UTC
Requires
- php: >=8.3
- ext-mbstring: *
- ext-openssl: *
- switon/core: ^1.0
Requires (Dev)
- switon/testing: ^1.0
README
Encryption, decryption, and key handling utilities for Switon Framework.
Installation
composer require switon/crypto
Requirements: PHP 8.3+, ext-openssl, ext-mbstring
Quick Start
use Switon\Core\Attribute\Autowired; use Switon\Crypto\CipherInterface; class UserProfileService { #[Autowired] protected CipherInterface $cipher; public function encryptProfile(int $userId, array $profile): string { return $this->cipher->encrypt( json_encode($profile, JSON_THROW_ON_ERROR), "user:{$userId}" ); } public function decryptProfile(int $userId, string $encrypted): array { $json = $this->cipher->decrypt($encrypted, "user:{$userId}", 'json'); return json_decode($json, true, flags: JSON_THROW_ON_ERROR); } }
Docs: https://docs.switon.dev/latest/crypto
License
MIT.