switon/crypto

Encryption, decryption, and key handling utilities for Switon Framework

Maintainers

Package info

github.com/switon-php/crypto

Documentation

pkg:composer/switon/crypto

Statistics

Installs: 2

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-09 23:36 UTC

This package is auto-updated.

Last update: 2026-05-10 02:46:18 UTC


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.