兰宝车间质量管理系统-前端
疯狂的狮子Li
2025-01-24 5682b5f9c26a0ac31e017dfce7d86d13ce118761
src/utils/crypto.ts
@@ -23,11 +23,18 @@
};
/**
 * 随机生成aes 密钥
 * 加密base64
 * @returns {string}
 */
export const encryptBase64 = (str: string) => {
export const encryptBase64 = (str: CryptoJS.lib.WordArray) => {
  return CryptoJS.enc.Base64.stringify(str);
};
/**
 * 解密base64
 */
export const decryptBase64 = (str: string) => {
  return CryptoJS.enc.Base64.parse(str);
};
/**
@@ -43,3 +50,17 @@
  });
  return encrypted.toString();
};
/**
 * 使用密钥对数据进行解密
 * @param message
 * @param aesKey
 * @returns {string}
 */
export const decryptWithAes = (message: string, aesKey: CryptoJS.lib.WordArray) => {
  const decrypted = CryptoJS.AES.decrypt(message, aesKey, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
};