@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
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
| Parameter | Type | Description |
|---|---|---|
options | CryptModuleOptions & 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
| Parameter | Type | Description |
|---|---|---|
options | ConfigurableModuleAsyncOptions<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
| Parameter | Type | Description |
|---|---|---|
options | CryptModuleOptions | Configuration options for the crypt service |
Returns
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
| Parameter | Type | Description |
|---|---|---|
value | string | The base64-encoded encrypted string to decrypt |
secret? | string | Optional 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
| Parameter | Type | Description |
|---|---|---|
value | string | The plaintext string to encrypt |
secret? | string | Optional 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.