# Fix "TypeError: crypto.createCipher is not a function" on Node.js 22

Yes. An agent ports createCipher to createCipheriv with the same derived key, proves old ciphertext still decrypts, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/fix-crypto-createcipher-is-not-a-function/crypto/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Node.js 22 removed `crypto.createCipher` and `crypto.createDecipher`. The usual advice is to switch to `createCipheriv`, and that is where data gets lost: the removed functions took a password and derived the key and the IV from it internally, while the replacement takes a key and an IV and derives nothing. Pass the password through any other derivation and everything encrypted before the upgrade becomes unreadable. bitpay/bitauth shows the shape of the job. `lib/encrypt.js` calls `crypto.createCipher('aes-256-cbc', password)` and returns the result base58-encoded, `lib/decrypt.js` reverses it with `createDecipher`, and `index.js` attaches both functions for Node only. Users encrypt their private keys with it, so the ciphertext already exists in places the repository will never see.

The agent runs `npm test`, which is `mocha`, on the Node version in the sandbox. Of the 25 tests in `test/test.bitauth.js`, 22 pass and three fail: one with the title's error at `lib/encrypt.js:5` and two with `crypto.createDecipher is not a function` at `lib/decrypt.js:5`. One of the three is the test that matters most, `should decrypt a previously known message`. It feeds a ciphertext constant stored in the test file to `decrypt` and expects the original sentence back. That constant is a recording of what the old function produced, which makes it the compatibility check for the port.

To keep it passing, the agent reproduces the old derivation exactly: OpenSSL's `EVP_BytesToKey` with MD5, one round and no salt. In code that is a short loop that hashes the previous digest plus the password until it has 48 bytes, the first 32 for the AES-256 key and the next 16 for the IV. It puts the loop in one helper beside the two files, calls `createCipheriv` and `createDecipheriv` with the result, and reruns the suite. With that helper in place all 25 tests pass, the old constant included.

It then says plainly what it preserved. A key from one unsalted MD5 pass is cheap to guess, and a fixed IV means the same password and message always give the same ciphertext, which is why Node deprecated the functions long before removing them. The agent does not change the format on its own. It proposes a second step in the pull request: a new versioned format with scrypt, a random salt and a random IV for everything encrypted from now on, with the legacy path kept for decryption only.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This project fails on Node.js 22 or later with \"TypeError: crypto.createCipher is not a function\" (or createDecipher). Fix it without making existing encrypted data unreadable. Find every call to crypto.createCipher and crypto.createDecipher, including in scripts and tests, and for each one record the algorithm, where the password comes from, the output encoding, and where the ciphertext ends up: a database column, a file, a cookie or token, or a value users keep themselves. Run the test suite first and report which failures are this error. Replace each call with createCipheriv or createDecipheriv using a key and IV derived exactly as the removed functions derived them (OpenSSL EVP_BytesToKey with MD5, one iteration, no salt, key and IV lengths taken from the algorithm), in one shared helper. Prove compatibility: if the repository has a recorded ciphertext, decrypt it; if it has none, say so, generate fixtures on a Node version that still has createCipher if one can be installed here, and add them as tests. Do not change the stored format in this pull request. Describe, as a follow-up, a versioned format with a salted key derivation such as scrypt and a random IV per message, how new and old values would be told apart, and how existing data could be re-encrypted. If the algorithm itself is unavailable in this Node's OpenSSL, report that as a separate problem. Run the tests again, state the Node version used, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that adds one helper file and changes one line in each caller. For bitauth that is `lib/encrypt.js`, `lib/decrypt.js` and the new key-derivation helper, with no change to `package.json`, since everything used is in Node's own `crypto` module. The description gives the test results before and after on the stated Node version, and names the known-ciphertext test as the evidence that values encrypted by earlier releases still decrypt.

It also carries an inventory: each call site, its algorithm, and where its output lives. That list is what tells a reviewer how careful to be. A session token that expires in an hour can change format freely. A column of encrypted phone numbers, or a string a user pasted into a password manager, cannot.

Before merging, a reviewer decrypts one real value from production with the branch, because a test fixture proves the algorithm and a production value proves the configuration around it. The proposed stronger format is left as a described follow-up for the team to accept or decline.

## Run it on every repository that still calls createCipher

The removal is tied to a runtime upgrade you schedule, so run this before the upgrade instead of after an outage. Search your organisation's code for `createCipher(` and `createDecipher(`, and for each repository found send `POST /o/{org}/sessions` with the body above and that repository in `resources`. Add a `request_id` that is a UUID v5 of the repository's full name, so running the script twice starts each job once. Starts past the key's concurrency limit are accepted and wait as `queued` until a slot frees.

Set a `webhook_url` on the API key to hear about each result. Every run the key starts posts `run.completed` or `run.failed` there, and the session it points to carries the pull request. Read the inventories before the diffs: the repositories whose ciphertext lives in a database are the ones to merge and verify first.

## Why run it on Rush?

This is a change where a green build can still mean lost data, and the only defence is to decrypt something old with the new code. The agent does that in its own sandbox, on a Node version that no longer has the removed functions, and the test output is kept with the session. A reviewer reads that 25 of 25 passed with the recorded ciphertext among them, and can see the command that produced the line.

It also resists the tempting fix. Search results for this error often suggest `createCipheriv` with a key from `scryptSync` and a random IV, which is better cryptography and silently abandons every existing value. An agent given the prompt above keeps the two questions apart, first making the upgrade safe and then describing the improvement, and writes down where each ciphertext lives so the people who own that data can decide.

## Frequently asked questions

### What replaced crypto.createCipher?

`crypto.createCipheriv(algorithm, key, iv)`, and `createDecipheriv` for the reverse. The difference is that you supply the key and IV as bytes of the right length for the algorithm. The removed functions accepted a password and produced both from it.

### Can I still decrypt data that was encrypted with createCipher?

Yes, if you derive the key and IV the way the old function did: repeated MD5 over the password with no salt, taking the key bytes first and the IV bytes after. With those values `createDecipheriv` returns the original plaintext. bitauth's own test of a previously known message passes on Node 22 with that derivation.

### Is it safe to keep using the old derivation?

It is no worse than what you had, and no better. A single unsalted MD5 pass makes passwords cheap to guess, and the fixed IV gives identical output for identical input. Treat the port as what lets you upgrade Node, and plan a new format for new data.

### Which Node.js versions have the problem?

Node.js 22 and later, where the two functions no longer exist. Earlier versions still have them and print a deprecation warning, DEP0106, when they are called. The `createCipheriv` form works on old and new versions alike, so the fix can ship before the runtime upgrade.

### Does this affect code that runs in the browser?

Only if a bundler shims Node's `crypto` module for it. In bitauth the encrypt and decrypt functions are attached in the Node branch of `index.js` and the browser build never loads them. The agent checks which entry points import the changed files and says so.

## More jobs like this: Fix a bug from an alert

- [Fix TypeError: crypto.hash Is Not a Function After a Vite 7 Upgrade](https://getrush.ai/run/fix-crypto-hash-is-not-a-function/vite/)
- [Fix "AttributeError: 'Cursor' object has no attribute 'count'" after a PyMongo upgrade](https://getrush.ai/run/fix-cursor-object-has-no-attribute-count/pymongo/)
- [Fix "d3.scale.linear is not a function" after upgrading D3 past version 3](https://getrush.ai/run/fix-d3-scale-linear-is-not-a-function/d3/)
- [Fix "database is locked" Errors in a GORM and SQLite App](https://getrush.ai/run/fix-database-is-locked/gorm/)
- [Fix an ASP.NET Core App Bug From a Datadog Monitor Alert](https://getrush.ai/run/fix-datadog-alerts/aspnet-core/)
- [Fix a Django App Bug From a Datadog Monitor Alert](https://getrush.ai/run/fix-datadog-alerts/django/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
