brainfoolong/js-aes-php
Composer 安装命令:
composer require brainfoolong/js-aes-php
包简介
Slim native AES encryption/decryption on client side with Javascript and on server side with PHP
关键字:
README 文档
README
Slim native AES encryption/decryption 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 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
- 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/Typescript, 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
- 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
- For Javascript: Any recent Browser 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
$value = ['foobar' => 'l`î', 'emojiiii' => '😊'];
$password = '😊Blub';
$encrypted = JsAesPhp::encrypt($value, $password);
$decrypted = JsAesPhp::decrypt($encrypted, $password);
Javascript/Typescript - 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
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: https://stackoverflow.com/questions/16600708/how-do-you-encrypt-and-decrypt-a-php-string/30159120#30159120
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 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 https://github.com/brainfoolong/php-ascon and https://github.com/brainfoolong/js-ascon
Changelog
1.0.4 and 1.0.5 - 2026-05-11
This release fixes and issue with running inside bun. Also the repository moved to codeberg and github now only mirrors the codeberg repo.
1.0.3 - 2026-03-03
- fixed support for typescript 5.9+ (type errors fixed with casts)
1.0.2 - 2024-12-20
- fixed support for web workers
1.0.1 - 2024-08-14
Initial Public Release
brainfoolong/js-aes-php 适用场景与选型建议
brainfoolong/js-aes-php 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 15.92k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「javascript」 「encryption」 「aes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 brainfoolong/js-aes-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brainfoolong/js-aes-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 brainfoolong/js-aes-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
统计信息
- 总下载量: 15.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-15