Legacy Crypto KeyGen
🚀 In Node.js 22, crypto.createCipher() is deprecated, breaking encryption compatibility with previous Node.js versions. This package generates legacy-style Key and IV, allowing you to decrypt data encrypted using older versions.
📌 Why This Package?
In many projects, we use the crypto module or third-party Node.js packages to encrypt and decrypt data. If your code uses modern APIs like crypto.createCipheriv(), there is no issue. However, older codebases often use the deprecated crypto.createCipher() and crypto.createDecipher() methods.
These methods were removed in Node.js v20 and above, which causes compatibility issues when running legacy code on newer Node versions. Specifically, passwords encrypted using createCipher() cannot be decrypted using createDecipheriv() due to differences in key derivation.
To solve this issue and maintain compatibility, we use a custom method that replicates the legacy OpenSSL key derivation logic. This allows us to generate consistent encryption keys and IVs from a password, ensuring that encrypted data can be decrypted correctly using both legacy (createCipher) and modern (createCipheriv) APIs.
How it works
This utility uses your original password to generate a consistent key and IV using a legacy MD5-based hash chaining technique, similar to OpenSSL’s EVP_BytesToKey method. These derived values are compatible with both crypto.createCipher() and crypto.createCipheriv(), making it possible to decrypt previously encrypted data even on modern Node.js versions.
📦 Installation
npm install legacy-crypto-keygenExamples
const { LegacyCrypto } = require("legacy-crypto-keygen");
const crypto = require("crypto");
// Example password
const password = "test-password";
const algorithm='aes-256-ctr'; // Example algorithm
// Create an instance of LegacyCrypto
const legacyCrypto = new LegacyCrypto(password);
// Generate Key and IV
const { key, iv } = legacyCrypto.generateKeyAndIv();
// Example decryption usage
const decipher = crypto.createDecipheriv(algorithm, key, iv);
console.log(decipher,"Decipher instance created successfully!");
function decryptPassword(pwd){
let decrypted = decipher.update(pwd, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}