PHPackages                             tourze/tls-crypto-symmetric - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tourze/tls-crypto-symmetric

ActiveLibrary

tourze/tls-crypto-symmetric
===========================

TLS对称加密算法实现

0.0.1(11mo ago)00MITPHPPHP ^8.1CI passing

Since May 23Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/tls-crypto-symmetric)[ Packagist](https://packagist.org/packages/tourze/tls-crypto-symmetric)[ RSS](/packages/tourze-tls-crypto-symmetric/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

TLS Crypto Symmetric
====================

[](#tls-crypto-symmetric)

[![PHP Version](https://camo.githubusercontent.com/c6a81ad6daf03a271e9bb8a8acfe9150bb6518eba29e5dba4c6acf621f603dc2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870)](https://www.php.net)[![License](https://camo.githubusercontent.com/422db9fd40f5831c765cf6530b6750c081b696bd18d904cf89554df98c676277/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e3f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/7dcd57f22e5d397a71b9698c80a53d43352412c41f6cb36ffd25cb56db0a2367/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo)[![Code Coverage](https://camo.githubusercontent.com/50a4fbc8e51d67d8814fd8ab90d2cbd132da38b8d00c18c96634f969c20867a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://codecov.io)

[English](README.md) | [中文](README.zh-CN.md)

TLS symmetric encryption algorithms implementation for PHP. This library provides a comprehensive set of symmetric encryption algorithms commonly used in TLS protocols.

Installation
------------

[](#installation)

```
composer require tourze/tls-crypto-symmetric
```

Quick Start
-----------

[](#quick-start)

```
use Tourze\TLSCryptoSymmetric\Cipher\AesGcm;

// Create AES-GCM cipher with 256-bit key
$cipher = new AesGcm(256);

// Prepare data
$plaintext = 'Hello, World!';
$key = random_bytes($cipher->getKeyLength());
$iv = random_bytes($cipher->getIVLength());
$aad = 'additional authenticated data';

// Encrypt
$ciphertext = $cipher->encrypt($plaintext, $key, $iv, $aad, $tag);

// Decrypt
$decrypted = $cipher->decrypt($ciphertext, $key, $iv, $aad, $tag);

echo $decrypted; // Hello, World!
```

Supported Algorithms
--------------------

[](#supported-algorithms)

- **AES-CBC**: Block cipher with Cipher Block Chaining mode
- **AES-CTR**: Block cipher with Counter mode
- **AES-GCM**: Authenticated encryption with Galois/Counter Mode
- **ChaCha20-Poly1305**: Stream cipher with Poly1305 authentication
- **3DES**: Triple Data Encryption Standard

Usage Examples
--------------

[](#usage-examples)

### AES-GCM (Recommended)

[](#aes-gcm-recommended)

```
use Tourze\TLSCryptoSymmetric\Cipher\AesGcm;

$cipher = new AesGcm(256); // 128, 192, or 256 bits
$key = random_bytes($cipher->getKeyLength());
$iv = random_bytes($cipher->getIVLength());

$ciphertext = $cipher->encrypt('sensitive data', $key, $iv, null, $tag);
$plaintext = $cipher->decrypt($ciphertext, $key, $iv, null, $tag);
```

### ChaCha20-Poly1305

[](#chacha20-poly1305)

```
use Tourze\TLSCryptoSymmetric\Cipher\ChaCha20Poly1305;

$cipher = new ChaCha20Poly1305();
$key = random_bytes($cipher->getKeyLength());
$iv = random_bytes($cipher->getIVLength());

$ciphertext = $cipher->encrypt('message', $key, $iv, 'aad', $tag);
$plaintext = $cipher->decrypt($ciphertext, $key, $iv, 'aad', $tag);
```

### AES-CBC

[](#aes-cbc)

```
use Tourze\TLSCryptoSymmetric\Cipher\AesCbc;

$cipher = new AesCbc(256);
$key = random_bytes($cipher->getKeyLength());
$iv = random_bytes($cipher->getIVLength());

$ciphertext = $cipher->encrypt('data', $key, $iv);
$plaintext = $cipher->decrypt($ciphertext, $key, $iv);
```

API Reference
-------------

[](#api-reference)

### CipherInterface

[](#cipherinterface)

All cipher implementations follow the `CipherInterface`:

```
interface CipherInterface
{
    public function getName(): string;
    public function getKeyLength(): int;
    public function getIVLength(): int;
    public function getBlockSize(): int;
    public function encrypt(string $plaintext, string $key, string $iv, ?string $aad = null, ?string &$tag = null): string;
    public function decrypt(string $ciphertext, string $key, string $iv, ?string $aad = null, ?string $tag = null): string;
}
```

### Exception Handling

[](#exception-handling)

The library throws `CipherException` for encryption/decryption errors:

```
use Tourze\TLSCryptoSymmetric\Exception\CipherException;

try {
    $result = $cipher->encrypt($data, $key, $iv);
} catch (CipherException $e) {
    echo 'Encryption failed: ' . $e->getMessage();
}
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- OpenSSL extension

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance63

Regular maintenance activity

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

354d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-tls-crypto-symmetric/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-tls-crypto-symmetric/health.svg)](https://phpackages.com/packages/tourze-tls-crypto-symmetric)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
