# demo-crypto-js **Repository Path**: consolelog/demo-crypto-js ## Basic Information - **Project Name**: demo-crypto-js - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-12-02 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DemoCryptoJs ``` npm i crypto-js npm i --save-dev @types/crypto-js import * as CryptoJS from 'crypto-js'; ngOnInit(): void { const key = 'bf960145b2a1338f'; const password = 'test123' const result = this.encrypt(password, key); console.log(result); const result1 = this.decrypt(result, key); console.log(result1); } encrypt(content, key): string { const key1 = CryptoJS.enc.Utf8.parse(key); const content1 = CryptoJS.enc.Utf8.parse(content); const result = CryptoJS.AES.encrypt(content1, key1, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return result.toString(); } decrypt(content, key): string { const key1 = CryptoJS.enc.Utf8.parse(key); const result = CryptoJS.AES.decrypt(content, key1, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return CryptoJS.enc.Utf8.stringify(result).toString(); } ```