Created
July 6, 2020 17:03
-
-
Save allenhwkim/318a29c9ac9af8fe8864dc2be1374feb to your computer and use it in GitHub Desktop.
Angular: Encrypt/Decrypt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nitin