Registry / security / mysql-aes

mysql-aes

JSON →
library0.1.0jsnpmunverified

Provides Node.js implementations of MySQL's AES_ENCRYPT and AES_DECRYPT functions, enabling encryption and decryption compatible with MySQL's block cipher mode. Version 0.1.0, last updated in 2016, is the only stable release. It is a lightweight library with no external dependencies, supporting ESM and CommonJS. Key differentiator: it mirrors MySQL's AES behavior exactly, using AES-128-ECB with PKCS7 padding and a specific key derivation, making it suitable for applications that need to encrypt/decrypt data consistently with MySQL. However, it is unmaintained and uses a weak cipher mode (ECB) that should not be used for new projects; use a more secure alternative.

npm install mysql-aes
INSTALL
IMPORT
SIG · MYSQL-AES
M
mysql-aes
securityjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import AES from 'mysql-aes'
✗ const AES = require('mysql-aes')
Library supports both ESM and CommonJS; use ESM for modern code.
AES.encrypt
✓ import AES from 'mysql-aes'; AES.encrypt(str, key)
✗ import { encrypt } from 'mysql-aes'
Only default export; named exports are not available.
AES.decrypt
✓ import AES from 'mysql-aes'; AES.decrypt(encrypted, key)
✗ const AES = require('mysql-aes'); AES.decrypt(encrypted, key)
Works with both ESM and CJS but CommonJS require is outdated.

Demonstrates encryption and decryption using AES.encrypt and AES.decrypt, matching MySQL's AES_ENCRYPT and AES_DECRYPT.

import AES from 'mysql-aes'; const key = 'mySecretKey12345'; const plaintext = 'Hello, MySQL!'; // Encrypt (returns hex string) const encrypted = AES.encrypt(plaintext, key); console.log('Encrypted (hex):', encrypted); // Decrypt const decrypted = AES.decrypt(encrypted, key); console.log('Decrypted:', decrypted); // 'Hello, MySQL!'
Debug
Known issues
deprecatedLibrary uses ECB mode, which is insecure for most use cases. AES-ECB does not provide semantic security; identical plaintext blocks produce identical ciphertext.
fix
Use a library that supports AES-GCM or AES-CBC with a random IV, such as Node.js built-in crypto module.
affects: >=0.0.0
breakingKey is hashed with MD5 before use; only first 16 bytes of MD5 hash are used as AES key. This is inconsistent with MySQL's actual key derivation in newer versions.
fix
If using MySQL 5.7+ with block_encryption_mode='aes-256-cbc', this library will not match MySQL's behavior. Use mysql2 or @mysql/xdevapi for proper encryption.
affects: >=0.0.0
deprecatedThe package has not been updated since 2016 and has no maintainer activity. It may contain unpatched vulnerabilities.
fix
Migrate to an actively maintained library like 'crypto' (Node.js built-in) or 'aes-js'.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: AES.encrypt is not a function
Incorrect import; named import used but only default export exists.
fix
Use: import AES from 'mysql-aes' then AES.encrypt(...)
Error: Decryption failed: invalid ciphertext
Ciphertext is not a proper hex string or was encrypted with a different key.
fix
Ensure ciphertext is hexadecimal (as returned by AES.encrypt) and use the exact same key.
Error: Key must be a string
Key argument provided is not a string (e.g., Buffer or number).
fix
Always pass key as a string: AES.encrypt(plaintext, String(key))
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
Resources