33** NestJS Encrytion** is a NestJS 9+ module that provides _ plug-and-play_ encryption
44and decryption functionality to your NestJS application.
55
6- - Uses ` AES -256-CBC ` by default, but supports [ other ciphers] ( #supported-ciphers ) as well.
6+ - Uses ` aes -256-cbc ` by default, but supports [ other ciphers] ( #supported-ciphers ) as well.
77- Provides a keygen (API and CLI) for generating random and secure encryption keys.
88- Thoroughly tested.
99
@@ -28,18 +28,18 @@ Setting up the module inside your NestJS application is a matter of registering
2828the module within your ` AppModule ` . The module is registered globally by default
2929and can be used anywhere in your application.
3030
31- You may use either the ` register ` or ` registerAsync ` method to register the module in your ` AppModule ` .
31+ You may use either the ` forRoot ` or ` forRootAsync ` method to register the module in your ` AppModule ` .
3232
33- ### Using ` register `
33+ ### Using ` forRoot `
3434
35- The ` register ` method is the simplest way to register the module.
35+ The ` forRoot ` method is the simplest way to register the module.
3636
3737``` typescript
3838import { EncryptionModule , Cipher } from " @hedger/nestjs-encryption" ;
3939
4040@Module ({
4141 imports: [
42- EncryptionModule .register ({
42+ EncryptionModule .forRoot ({
4343 key: process .env .APP_KEY ,
4444 cipher: Cipher .AES_256_CBC ,
4545 }),
@@ -48,9 +48,9 @@ import { EncryptionModule, Cipher } from "@hedger/nestjs-encryption";
4848export class AppModule {}
4949```
5050
51- ### Using ` registerAsync `
51+ ### Using ` forRootAsync `
5252
53- The ` registerAsync ` method allows you to register the module asynchronously,
53+ The ` forRootAsync ` method allows you to register the module asynchronously,
5454optionally resolving the encryption key from a configuration service. Here's
5555an example that uses the ` ConfigService ` from ` @nestjs/config ` to resolve the
5656encryption key from the ` APP_KEY ` environment variable.
@@ -61,11 +61,12 @@ import { EncryptionModule, Cipher } from "@hedger/nestjs-encryption";
6161
6262@Module ({
6363 imports: [
64- ConfigModule .forRoot (),
65- EncryptionModule .registerAsync ({
66- useFactory : (config : ConfigService ) => ({
67- key: config .get (" APP_KEY" ),
68- cipher: Cipher .AES_256_CBC ,
64+ ConfigModule .forRoot ({
65+ isGlobal: true ,
66+ }),
67+ EncryptionModule .forRootAsync ({
68+ useFactory : (configService : ConfigService ) => ({
69+ key: configService .get <string >(" APP_KEY" ),
6970 }),
7071 inject: [ConfigService ],
7172 }),
0 commit comments