跳到主要内容

@nest-boot/crypt

Classes

CryptModule

Defined in: packages/crypt/src/crypt.module.ts:30

Module that provides encryption and decryption services using AES-256-GCM.

Example

import { CryptModule } from '@nest-boot/crypt';

@Module({
imports: [
CryptModule.register({
secret: 'your-secret-key',
isGlobal: true,
}),
],
})
export class AppModule {}

Extends

  • ConfigurableModuleClass

Indexable

[key: string]: any

Constructors

Constructor
new CryptModule(): CryptModule;

Defined in: node_modules/.pnpm/@nestjs+common@11.1.9/node_modules/@nestjs/common/module-utils/interfaces/configurable-module-cls.interface.d.ts:12

Returns

CryptModule

Inherited from
ConfigurableModuleClass.constructor

Methods

register()
static register(options): DynamicModule;

Defined in: packages/crypt/src/crypt.module.ts:36

Registers the CryptModule with the given options.

Parameters
ParameterTypeDescription
optionsCryptModuleOptions & Partial<{ }>Configuration options including secret and isGlobal
Returns

DynamicModule

Dynamic module configuration

Overrides
ConfigurableModuleClass.register
registerAsync()
static registerAsync(options): DynamicModule;

Defined in: packages/crypt/src/crypt.module.ts:45

Registers the CryptModule asynchronously with factory functions.

Parameters
ParameterTypeDescription
optionsConfigurableModuleAsyncOptions<CryptModuleOptions, "create"> & Partial<{ }>Async configuration options
Returns

DynamicModule

Dynamic module configuration

Overrides
ConfigurableModuleClass.registerAsync

CryptService

Defined in: packages/crypt/src/crypt.service.ts:36

Service that provides encryption and decryption functionality using AES-256-GCM algorithm.

Example

import { CryptService } from '@nest-boot/crypt';

@Injectable()
export class MyService {
constructor(private readonly cryptService: CryptService) {}

async encryptData(data: string): Promise<string> {
return this.cryptService.encrypt(data);
}

async decryptData(encrypted: string): Promise<string> {
return this.cryptService.decrypt(encrypted);
}
}

Constructors

Constructor
new CryptService(options): CryptService;

Defined in: packages/crypt/src/crypt.service.ts:54

Creates an instance of CryptService.

Parameters
ParameterTypeDescription
optionsCryptModuleOptionsConfiguration options for the crypt service
Returns

CryptService

Throws

Error if no secret is provided via options or environment variables

Methods

decrypt()
decrypt(value, secret?): Promise<string>;

Defined in: packages/crypt/src/crypt.service.ts:103

Decrypts an encrypted string value.

Parameters
ParameterTypeDescription
valuestringThe base64-encoded encrypted string to decrypt
secret?stringOptional secret key to use instead of the default
Returns

Promise<string>

The decrypted plaintext string

encrypt()
encrypt(value, secret?): Promise<string>;

Defined in: packages/crypt/src/crypt.service.ts:77

Encrypts a string value using AES-256-GCM algorithm.

Parameters
ParameterTypeDescription
valuestringThe plaintext string to encrypt
secret?stringOptional secret key to use instead of the default
Returns

Promise<string>

A base64-encoded encrypted string containing IV, auth tag, data, and salt

Interfaces

CryptModuleOptions

Defined in: packages/crypt/src/crypt-module-options.interface.ts:4

Configuration options for the CryptModule.

Properties

secret?
optional secret: string;

Defined in: packages/crypt/src/crypt-module-options.interface.ts:9

The secret key used for encryption and decryption. If not provided, falls back to CRYPT_SECRET or APP_SECRET environment variables.