{"id":43246,"library":"mysql-aes","title":"mysql-aes","description":"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.","status":"deprecated","version":"0.1.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/magicdawn/node-mysql-aes","tags":["javascript","mysql","crypto","aes","aes_encrypt","aes_decrypt","typescript"],"install":[{"cmd":"npm install mysql-aes","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-aes","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-aes","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Library supports both ESM and CommonJS; use ESM for modern code.","wrong":"const AES = require('mysql-aes')","symbol":"default","correct":"import AES from 'mysql-aes'"},{"note":"Only default export; named exports are not available.","wrong":"import { encrypt } from 'mysql-aes'","symbol":"AES.encrypt","correct":"import AES from 'mysql-aes'; AES.encrypt(str, key)"},{"note":"Works with both ESM and CJS but CommonJS require is outdated.","wrong":"const AES = require('mysql-aes'); AES.decrypt(encrypted, key)","symbol":"AES.decrypt","correct":"import AES from 'mysql-aes'; AES.decrypt(encrypted, key)"}],"quickstart":{"code":"import AES from 'mysql-aes';\n\nconst key = 'mySecretKey12345';\nconst plaintext = 'Hello, MySQL!';\n\n// Encrypt (returns hex string)\nconst encrypted = AES.encrypt(plaintext, key);\nconsole.log('Encrypted (hex):', encrypted);\n\n// Decrypt\nconst decrypted = AES.decrypt(encrypted, key);\nconsole.log('Decrypted:', decrypted); // 'Hello, MySQL!'","lang":"typescript","description":"Demonstrates encryption and decryption using AES.encrypt and AES.decrypt, matching MySQL's AES_ENCRYPT and AES_DECRYPT."},"warnings":[{"fix":"Use a library that supports AES-GCM or AES-CBC with a random IV, such as Node.js built-in crypto module.","message":"Library uses ECB mode, which is insecure for most use cases. AES-ECB does not provide semantic security; identical plaintext blocks produce identical ciphertext.","severity":"deprecated","affected_versions":">=0.0.0"},{"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.","message":"Key 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.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Migrate to an actively maintained library like 'crypto' (Node.js built-in) or 'aes-js'.","message":"The package has not been updated since 2016 and has no maintainer activity. It may contain unpatched vulnerabilities.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'-128':62 '0.1.0':28 '2016':32 'ae':3,10,13,57,61,112,113,115 'altern':108 'applic':76 'behavior':58 'block':24 'cipher':25,93 'commonj':50 'compat':20 'consist':82 'crypto':111 'data':81 'decrypt':14,19,116 'depend':46 'deriv':71 'differenti':52 'ecb':63,95 'enabl':16 'encrypt':11,17,114 'encrypt/decrypt':80 'esm':48 'exact':59 'extern':45 'function':15 'howev':85 'implement':6 'javascript':109 'key':51,70 'last':29 'librari':42 'lightweight':41 'make':72 'mirror':54 'mode':26,94 'mysql':2,8,22,55,84,110 'mysql-a':1 'need':78 'new':102 'node.js':5 'pad':66 'pkcs7':65 'project':103 'provid':4 'releas':37 'secur':107 'specif':69 'stabl':36 'suitabl':74 'support':47 'typescript':117 'unmaintain':88 'updat':30 'use':60,90,100,104 'version':27 'weak':92","created_at":"2026-06-05T16:58:53.005209+00:00","updated_at":"2026-06-05T16:58:53.005209+00:00","problems":[{"fix":"Use: import AES from 'mysql-aes' then AES.encrypt(...)","cause":"Incorrect import; named import used but only default export exists.","error":"TypeError: AES.encrypt is not a function"},{"fix":"Ensure ciphertext is hexadecimal (as returned by AES.encrypt) and use the exact same key.","cause":"Ciphertext is not a proper hex string or was encrypted with a different key.","error":"Error: Decryption failed: invalid ciphertext"},{"fix":"Always pass key as a string: AES.encrypt(plaintext, String(key))","cause":"Key argument provided is not a string (e.g., Buffer or number).","error":"Error: Key must be a string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/magicdawn/node-mysql-aes#readme","github":"ssh://git@github.com/magicdawn/node-mysql-aes","docs":null,"changelog":null,"pypi":null,"npm":"mysql-aes","openapi_spec":null,"status_page":null,"smithery":null,"categories":["security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}