I'm using Vue and Typescript in my client side, I assume the client side code can return the same result as the server side function, but it does not work.(When passing the same params to the two functions, the results are different. )
// server side
import crypto from 'crypto';
const cipherPwd = (pwd, key) => {
const ciph = crypto.createCipher("aes192", key);
return ciph.update(pwd, "utf8", "base64") + ciph.final("base64");
};
// client side (using crypto-js because crypto can't be used in client)
import CryptoJS from 'crypto-js';
private cipherPwd(pwd: string, key: string): string {
const keyArr = CryptoJS.enc.Utf8.parse(key);
const ivArr = CryptoJS.enc.Utf8.parse('');
const json = CryptoJS.AES.encrypt(pwd, keyArr, { iv: ivArr });
return json.ciphertext.toString(CryptoJS.enc.Base64);
}