PHPackages                             sop/gcm - 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. [Security](/categories/security)
4. /
5. sop/gcm

ActiveLibrary[Security](/categories/security)

sop/gcm
=======

A PHP library for Galois/Counter Mode encryption with AES.

3.0.0(6y ago)5258.6k↓31.6%2[1 PRs](https://github.com/sop/gcm/pulls)1MITPHPPHP &gt;=7.2

Since May 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/sop/gcm)[ Packagist](https://packagist.org/packages/sop/gcm)[ Docs](https://github.com/sop/gcm)[ RSS](/packages/sop-gcm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (11)Used By (1)

GCM
===

[](#gcm)

[![Build Status](https://camo.githubusercontent.com/356ca4ef54716b9729e152467bfa7fc720a841e9f85b01c50c223f26bb9ee854/68747470733a2f2f7472617669732d63692e6f72672f736f702f67636d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sop/gcm)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/18df7079eefef67c1a01f82b1af8655f623dd8eaf2ac1c1f800123c6d3b45ed3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f702f67636d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sop/gcm/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/459c82cf9f7639b2d549a9d824078888e8dc0cb54c8940069f16cf6991f5b48d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736f702f67636d2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sop/gcm?branch=master)[![License](https://camo.githubusercontent.com/29b21f62e2578dfd697f28dd07dcbc6241fb66bd9a9e01d99fdada0aec4576e0/68747470733a2f2f706f7365722e707567782e6f72672f736f702f67636d2f6c6963656e7365)](https://github.com/sop/gcm/blob/master/LICENSE)

A PHP library for Galois/Counter Mode ([GCM](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf)) encryption.

Supports AES-GCM with 128, 192 and 256-bit key sizes and specified authentication tag lengths.

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

[](#requirements)

- PHP &gt;=7.2
- openssl
- hash
- gmp

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

[](#installation)

This library is available on [Packagist](https://packagist.org/packages/sop/gcm).

```
composer require sop/gcm

```

Code examples
-------------

[](#code-examples)

Here are some simple usage examples. Namespaces are omitted for brevity.

### Encrypt

[](#encrypt)

Encrypt a message with additional authenticated data, using a 128-bit key.

```
[$ciphertext, $auth_tag] = AESGCM::encrypt(
    'Meet me at the pier at midnight.',
    'Additional info', 'some 128 bit key', 'random iv-string');
echo bin2hex($ciphertext) . "\n" . bin2hex($auth_tag);
```

Outputs:

```
5a24cfccf2e6c7763f71cd2ef6bcaa78385b16328593a93a43146d587e314ed8
389cc23f815d453686915530937d2053

```

See [`/examples`](https://github.com/sop/gcm/blob/master/examples/encrypt.php) for a detailed version.

### Decrypt

[](#decrypt)

Decrypt a ciphertext created above. Additional authenticated data must be the same, otherwise authentication fails and an exception shall be thrown.

```
$plaintext = AESGCM::decrypt($ciphertext, $auth_tag,
    'Additional info', 'some 128 bit key', 'random iv-string');
echo $plaintext;
```

Outputs:

```
Meet me at the pier at midnight.

```

See [`/examples`](https://github.com/sop/gcm/blob/master/examples/decrypt.php) for a detailed version.

### Using explicit cipher method and tag length

[](#using-explicit-cipher-method-and-tag-length)

[Encrypt](https://github.com/sop/gcm/blob/master/examples/explicit-encrypt.php)a message without additional authenticated data using AES-192 as an underlying cipher and produce a 104-bit (13 bytes) authentication tag.

```
$key = '012345678901234567890123'; // 192-bit encryption key
$iv = hex2bin('beadfacebadc0fee'); // random initialization vector
$gcm = new GCM(new AES192Cipher(), 13);
[$ciphertext, $auth_tag] = $gcm->encrypt('Secret message.', '', $key, $iv);
echo bin2hex($ciphertext) . "\n" . bin2hex($auth_tag);
```

Outputs:

```
7bcd4e423016213c60a3c0a3e3fc0c
027b14cfea0a2307649fc67b1d

```

[Decrypting](https://github.com/sop/gcm/blob/master/examples/explicit-decrypt.php)the output from above.

```
$plaintext = $gcm->decrypt($ciphertext, $auth_tag, '', $key, $iv);
echo $plaintext;
```

Outputs:

```
Secret message.

```

References
----------

[](#references)

- [GCM Specification](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf)
- [NIST Special Publication 800-38D](http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf)

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~136 days

Recently: every ~266 days

Total

9

Last Release

2553d ago

Major Versions

0.2.2 → 1.0.02016-06-20

1.0.2 → 2.0.02017-11-28

2.0.0 → 3.0.02019-05-23

PHP version history (3 changes)0.1.0PHP &gt;=5.6.3

2.0.0PHP &gt;=7.0

3.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/35cf70dd6be68d37fd42490e3ad9c199d2a1f1dd4420f71658998b7d8b694e97?d=identicon)[sop](/maintainers/sop)

---

Top Contributors

[![sop](https://avatars.githubusercontent.com/u/1017000?v=4)](https://github.com/sop "sop (55 commits)")

---

Tags

aesaes-gcmdecryptencryptgcmaesencryptdecryptgcmGalois Counter ModeAES-GCMgalois

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sop-gcm/health.svg)

```
[![Health](https://phpackages.com/badges/sop-gcm/health.svg)](https://phpackages.com/packages/sop-gcm)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[spomky-labs/php-aes-gcm

AES GCM (Galois Counter Mode) PHP implementation.

724.9M20](/packages/spomky-labs-php-aes-gcm)[nzo/url-encryptor-bundle

The NzoUrlEncryptorBundle is a Symfony Bundle used to Encrypt and Decrypt data and variables in the Web application or passed through URL

961.0M2](/packages/nzo-url-encryptor-bundle)[mmeyer2k/dcrypt

A petite library of encryption functionality for PHP

98727.2k1](/packages/mmeyer2k-dcrypt)[miladrahimi/phpcrypt

Encryption, decryption, and hashing tools for PHP projects

3171.5k2](/packages/miladrahimi-phpcrypt)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

127.8k1](/packages/poly-crypto-poly-crypto)

PHPackages © 2026

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