abs-nestjs-cipher-service
v0.0.2
Published
This documentation provides instructions on how to use the Cipher Service based on the code in the test directory.
Readme
Cipher Service Documentation
This documentation provides instructions on how to use the Cipher Service based on the code in the test directory.
Installation
To install the necessary dependencies, run:
npm install abs-nestjs-cipher-serviceUsage with NestJS
Setting Up the Cipher Service
Setup the SYSTEM_ENCRYPTION_KEY variable (must be 32 characters encoded to base64) in your .env
To use the Cipher Service in your NestJS application, you need to import and provide it in your module.
import { Module } from '@nestjs/common';
import { CipherService } from 'abs-nestjs-cipher-service';
@Module({
providers: [CipherService],
exports: [CipherService],
})
export class AppModule {}Encrypting Data
To encrypt data, inject the CipherService into your service or controller and use the encrypt method. Below is an example:
import { Injectable } from '@nestjs/common';
import { CipherService } from 'abs-nestjs-cipher-service';
@Injectable()
export class AppService {
constructor(private readonly cipherService: CipherService) {}
encryptData(data: string): string {
return this.cipherService.encrypt(data);
}
}Decrypting Data
To decrypt data, inject the CipherService into your service or controller and use the decrypt method. Below is an example:
import { Injectable } from '@nestjs/common';
import { CipherService } from 'abs-nestjs-cipher-service';
@Injectable()
export class AppService {
constructor(private readonly cipherService: CipherService) {}
decryptData(encryptedData: string): string {
return this.cipherService.decrypt(encryptedData);
}
}License
This project is licensed under the MIT License.
