PHPackages                             brainfoolong/js-aes-php - 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. brainfoolong/js-aes-php

ActiveLibrary[Security](/categories/security)

brainfoolong/js-aes-php
=======================

Slim native AES encryption/decryption on client side with Javascript and on server side with PHP

1.0.1(1y ago)1311.8k↓50%MITTypeScriptPHP &gt;=8.0.0CI passing

Since Aug 15Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/brainfoolong/js-aes-php)[ Packagist](https://packagist.org/packages/brainfoolong/js-aes-php)[ Docs](https://github.com/brainfoolong/js-aes-php)[ GitHub Sponsors](https://github.com/brainfoolong)[ RSS](/packages/brainfoolong-js-aes-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (2)Used By (0)

[![PHP and JS Tests](https://github.com/brainfoolong/js-aes-php/actions/workflows/test-php-js.yml/badge.svg)](https://github.com/brainfoolong/js-aes-php/actions/workflows/test-php-js.yml)[![Browser Tests](https://github.com/brainfoolong/js-aes-php/actions/workflows/test-browser.yml/badge.svg)](https://github.com/brainfoolong/js-aes-php/actions/workflows/test-browser.yml)

Slim native AES encryption/decryption on client side with Javascript and on server side with PHP
================================================================================================

[](#slim-native-aes-encryptiondecryption-on-client-side-with-javascript-and-on-server-side-with-php)

A tool to AES encrypt/decrypt data in javascript and/or PHP. You can use it for PHP only, for Javascript only or mix it together.

It uses `aes-256-cbc` implementation with random salts and random initialization vector. This library does not support other ciphers or modes.

This library is the successor to my previous [CryptoJs-Aes-Php](https://github.com/brainfoolong/cryptojs-aes-php) encryption library that required CryptoJS. This library does not require any third party dependency as modern browsers and Node now have proper crypto tools built in. Attention: This library does output different encryption values to my previous library, it cannot be a drop-in replacement.

### Features

[](#features)

- Encrypt any value in Javascript (objects/array/etc...) - Everything that can be passed to JSON.stringify
- Encrypt any value in PHP (object/array/etc...) - Everything that can be passed to json\_encode
- Decrypt in PHP/Javascript, doesn't matter where you have encrypted the values
- Easy store and transfer the encrypted values, the encrypted output only contains hex characters (0-9 A-F)
- Small footprint: 5kb unzipped Javascript file

### Install

[](#install)

- Bun: `bun install js-aes-php`
- NPM: `npm i js-aes-php`
- Composer: `composer require brainfoolong/js-aes-php`
- Or just download the latest release zip for everything at once

### Requirements

[](#requirements)

- For Javascript: Any [recent Browser](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#browser_compatibility) or Node environment (15+)
- For Typescript: Use `src/ts/js-aes-php.ts`
- For PHP: 8.0 or above with OpenSSL extension enabled

### PHP - How to use

[](#php---how-to-use)

```
$value = ['foobar' => 'l`î', 'emojiiii' => '😊'];
$password = '😊Blub';
$encrypted = JsAesPhp::encrypt($value, $password);
$decrypted = JsAesPhp::decrypt($encrypted, $password);
```

### Javascript/Typescript - How to use

[](#javascripttypescript---how-to-use)

```
const value = { 'foobar': 'l`î', 'emojiiii': '😊' }
const password = '😊Blub'
const encrypted = await JsAesPhp.encrypt(value, password)
const decrypted = await JsAesPhp.decrypt(encrypted, password)
```

### Security Notes

[](#security-notes)

This library use AES-256-CBC encryption, which is still good and safe but there are (maybe) better alternatives for your use case. If you require really high security, you should invest more time for what is suitable for you.

Also, there's a good article about PHP issues/info related to this library:

### Alternatives - ASCON

[](#alternatives---ascon)

You may wonder if there are alternatives to AES encryption that you can use in PHP/JS. ASCON is a newer, lightweight cipher that have been selected in 2023 by the [NIST](https://csrc.nist.gov/projects/lightweight-cryptography) as the new standard for lightweight cryptography, which may suite your needs. I have created libraries for both PHP and JS which you can find at  and

### Changelog

[](#changelog)

#### 1.0.3 - 2026-03-03

[](#103---2026-03-03)

- fixed support for typescript 5.9+ (type errors fixed with casts)

#### 1.0.2 - 2024-12-20

[](#102---2024-12-20)

- fixed support for web workers

#### 1.0.1 - 2024-08-14

[](#101---2024-08-14)

Initial Public Release

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance62

Regular maintenance activity

Popularity33

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

641d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1684236?v=4)[Roland Eigelsreiter](/maintainers/BrainFooLong)[@brainfoolong](https://github.com/brainfoolong)

---

Top Contributors

[![brainfoolong](https://avatars.githubusercontent.com/u/1684236?v=4)](https://github.com/brainfoolong "brainfoolong (28 commits)")

---

Tags

aes-encryptionjavascriptphptypescriptphpjavascriptencryptionaes

### Embed Badge

![Health badge](/badges/brainfoolong-js-aes-php/health.svg)

```
[![Health](https://phpackages.com/badges/brainfoolong-js-aes-php/health.svg)](https://phpackages.com/packages/brainfoolong-js-aes-php)
```

###  Alternatives

[poly-crypto/poly-crypto

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

127.8k1](/packages/poly-crypto-poly-crypto)[stymiee/php-simple-encryption

The PHP Simple Encryption library is designed to simplify the process of encrypting and decrypting data while ensuring best practices are followed. By default is uses a secure encryption algorithm and generates a cryptologically strong initialization vector so developers do not need to becomes experts in encryption to securely store sensitive data.

448.0k](/packages/stymiee-php-simple-encryption)

PHPackages © 2026

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