0.0.5 • Published 3 years ago

nestjs-aes-gcm v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Installation

npm:

npm i nestjs-aes-gcm

yan

yan add nestjs-aes-gcm

Configure

app.module.ts

...
@Module({
	...
	imports: [
		...
		AesGcmModule.forRoot({
			// Default Options
			key: 'SECRET_KEY', /* optional */
			salt: 64, /* opcional */
			iv: 16, /* optional */
			encoding: 'hex', /* optional */
		}),
		...
		// For asynchronous configuration
		...
		AesGcmModule.forRootAsync({
			import: [ConfigModule],
			useFactory: (config: ConfigService) => ({
				key: config.get('SECRET_KEY')
			})
			inject: [ConfigService]
		}),
		...
		// OR
		AesGcmModule.forRootAsync({
			useClass: AesGcmConfigClass
		}),
		...
	],
	...
})
...

your.service.ts

...
@Injectable()
export class YourService{
	constructor(private readonly aesGcmService: AesGcmService) {}

	async encrypt(text: string): Promise<string> {
		return await this.aesGcmService.encrypt(text);
	}

	encryptSync(text: string): string {
		return this.aesGcmService.encrypt(text);
	}

	async decryption(encrypted: string): Promise<string> {
		return  await this.aesGcmService.decrypt(encrypted);
	}

	decryptionSync(encrypted: string): string {
		return this.aesGcmService.decrypt(encrypted);
	}

	async generateRandomKey(len: number /* default: 32 */): Promise<string> {
		return await this.aesGcmService.generateRandomKey(len);
	}

	generateRandomKeySync(len: number): string {
		return this.aesGcmService.generateRandomKeySync(len);
	}

	hash(data: string, algorithm: string /* default: sha256 */): string {
		return this.aesGcmService.hash(data, algorithm);
	}
}
...

Use Asynchronous methods for better performance

0.0.5

3 years ago

0.0.3

3 years ago

0.0.25

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago