Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Created July 6, 2020 17:03
Show Gist options
  • Save allenhwkim/318a29c9ac9af8fe8864dc2be1374feb to your computer and use it in GitHub Desktop.
Save allenhwkim/318a29c9ac9af8fe8864dc2be1374feb to your computer and use it in GitHub Desktop.
Angular: Encrypt/Decrypt
import { Pipe, PipeTransform } from '@angular/core';
import * as CryptoJS from 'crypto-js';
const key = 'TUc0emRqRXpkdw==';
@Pipe({name: 'encrypted'})
export class EncryptPipe implements PipeTransform {
transform(value: string) {
if (value) {
return CryptoJS.AES.encrypt(value, key).toString();
}
}
}
@Pipe({name: 'decrypted'})
export class DecryptPipe implements PipeTransform {
transform(encrypted: string) {
if (encrypted) {
const decrypted = CryptoJS.AES.decrypt(encrypted, key);
return decrypted.toString(CryptoJS.enc.Utf8);
}
}
}
@surosenn
Copy link

nitin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment