This file contains hidden or 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 CryptoJS from 'crypto-js'; | |
export function encryptText(keyStr, text) { | |
const private_key = CryptoJS.SHA256(keyStr).toString(CryptoJS.enc.Latin1); | |
const rem = text.length % 16; | |
const padded = CryptoJS.enc.Latin1.parse(text.padEnd(text.length + (16 - rem), '\0')); | |
const iv = CryptoJS.lib.WordArray.random(16); | |
const cipher = CryptoJS.AES.encrypt(padded, CryptoJS.enc.Latin1.parse(private_key), { | |
iv: iv, | |
mode: CryptoJS.mode.CFB, |