> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nodejs/userland-migrations/llms.txt
> Use this file to discover all available pages before exploring further.

# createCredentials Migration (DEP0010)

> Migrate from deprecated crypto.createCredentials to tls.createSecureContext for TLS credential management

This recipe transforms deprecated `crypto.createCredentials` usage to the modern `tls.createSecureContext` API for managing TLS credentials.

## What It Does

The codemod transforms:

* Imports from `node:crypto` → `node:tls`
* `createCredentials` function → `createSecureContext`
* All function calls to use the new API

## Usage

```bash theme={null}
npx codemod nodejs/createCredentials-to-createSecureContext
```

## Examples

<Tabs>
  <Tab title="CommonJS">
    ```javascript Before theme={null}
    // Using the deprecated createCredentials from node:crypto
    const { createCredentials } = require('node:crypto');

    const credentials = createCredentials({
      key: privateKey,
      cert: certificate,
      ca: [caCertificate]
    });
    ```

    ```javascript After theme={null}
    // Updated to use createSecureContext from node:tls
    const { createSecureContext } = require('node:tls');

    const credentials = createSecureContext({
      key: privateKey,
      cert: certificate,
      ca: [caCertificate]
    });
    ```
  </Tab>

  <Tab title="ESM">
    ```javascript Before theme={null}
    import { createCredentials } from 'node:crypto';

    const credentials = createCredentials({
      key: privateKey,
      cert: certificate,
      ca: [caCertificate]
    });
    ```

    ```javascript After theme={null}
    import { createSecureContext } from 'node:tls';

    const credentials = createSecureContext({
      key: privateKey,
      cert: certificate,
      ca: [caCertificate]
    });
    ```
  </Tab>
</Tabs>

## Options

The `createSecureContext` function accepts the same options as the deprecated `createCredentials`:

* `key` - Private key in PEM format
* `cert` - Certificate chain in PEM format
* `ca` - Array of trusted CA certificates
* `pfx` - PFX or PKCS12 encoded private key and certificate chain
* `passphrase` - Passphrase for the private key or pfx
* `ciphers` - Cipher suite specification
* `honorCipherOrder` - Use server's cipher preferences
* `secureProtocol` - SSL method to use
* And more - see [Node.js TLS documentation](https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions)

## Why Migrate?

<Warning>
  `crypto.createCredentials` was deprecated in Node.js v0.11.13 and may be removed in future versions.
</Warning>

Migrating to `tls.createSecureContext`:

* Uses the correct module (`tls` instead of `crypto`)
* Aligns with Node.js best practices
* Provides better semantic clarity about the function's purpose
* Ensures compatibility with future Node.js versions

<Tip>
  The `tls.createSecureContext` function is the standard way to create credentials for TLS servers and clients in Node.js.
</Tip>

## Common Use Cases

### HTTPS Server

```javascript theme={null}
import { createSecureContext } from 'node:tls';
import { createServer } from 'node:https';
import { readFileSync } from 'node:fs';

const credentials = createSecureContext({
  key: readFileSync('private-key.pem'),
  cert: readFileSync('certificate.pem')
});

const server = createServer({ secureContext: credentials }, (req, res) => {
  res.writeHead(200);
  res.end('Hello secure world!');
});
```

### TLS Socket

```javascript theme={null}
import { connect } from 'node:tls';
import { createSecureContext } from 'node:tls';

const context = createSecureContext({
  ca: [caCert]
});

const socket = connect({
  host: 'example.com',
  port: 8000,
  secureContext: context
});
```

## Deprecation Reference

This migration addresses [DEP0010](https://nodejs.org/api/deprecations.html#DEP0010).
