> ## 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.

# crypto.fips Migration (DEP0093)

> Migrate from deprecated crypto.fips property to crypto.getFips() and crypto.setFips() methods

This recipe transforms usage of the deprecated `crypto.fips` property to use the modern `crypto.getFips()` and `crypto.setFips()` methods.

## What It Does

The codemod transforms:

* Reading `crypto.fips` → `crypto.getFips()`
* Writing `crypto.fips = value` → `crypto.setFips(value)`
* Import statements to include `getFips` and `setFips`

## Usage

```bash theme={null}
npx codemod nodejs/crypto-fips-to-getFips
```

## Examples

### Reading FIPS Mode Status

```javascript Before theme={null}
import crypto from "node:crypto";
import { fips } from "node:crypto";

// Using crypto.fips
crypto.fips;
fips;
```

```javascript After theme={null}
import crypto from "node:crypto";
import { getFips, setFips } from "node:crypto";

// Using crypto.getFips()
crypto.getFips();
getFips();
```

### Enabling FIPS Mode

```javascript Before theme={null}
import crypto from "node:crypto";
import { fips } from "node:crypto";

// Using crypto.fips = true
crypto.fips = true;
fips = true;
```

```javascript After theme={null}
import crypto from "node:crypto";
import { getFips, setFips } from "node:crypto";

// Using crypto.setFips(true)
crypto.setFips(true);
setFips(true);
```

### Disabling FIPS Mode

```javascript Before theme={null}
import crypto from "node:crypto";
import { fips } from "node:crypto";

// Using crypto.fips = false
crypto.fips = false;
fips = false;
```

```javascript After theme={null}
import crypto from "node:crypto";
import { getFips, setFips } from "node:crypto";

// Using crypto.setFips(false)
crypto.setFips(false);
setFips(false);
```

## What is FIPS Mode?

FIPS (Federal Information Processing Standards) mode enables cryptographic operations that comply with FIPS 140-2 requirements. When enabled:

* Only FIPS-approved cryptographic algorithms are available
* Node.js must be built with FIPS support
* Useful for applications requiring government-standard cryptography

<Tip>
  FIPS mode can only be enabled at startup or if Node.js was built with FIPS support. Check if FIPS is available using `crypto.getFips()`.
</Tip>

## Why Migrate?

<Warning>
  The `crypto.fips` property was deprecated in Node.js v10.0.0. Using property accessors for FIPS mode is not recommended.
</Warning>

Migrating to the getter/setter methods:

* Provides explicit method calls for better code clarity
* Aligns with Node.js API conventions
* Enables better error handling
* Ensures compatibility with future Node.js versions

## Common Usage Patterns

### Check and Enable FIPS

```javascript theme={null}
import { getFips, setFips } from 'node:crypto';

if (!getFips()) {
  try {
    setFips(true);
    console.log('FIPS mode enabled');
  } catch (err) {
    console.error('Failed to enable FIPS mode:', err);
  }
}
```

### Conditional FIPS Mode

```javascript theme={null}
import { setFips } from 'node:crypto';

if (process.env.ENABLE_FIPS === 'true') {
  setFips(true);
}
```

## Deprecation Reference

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

## Related APIs

* `crypto.getFips()` - Returns the current FIPS mode status (boolean)
* `crypto.setFips(bool)` - Enables or disables FIPS mode
* Node.js must be compiled with `--openssl-fips` for FIPS support
