| 1234567891011121314151617181920212223242526 |
- import CryptoJS from 'crypto-js';
-
- // 加密密钥
- const ENCRYPTION_KEY = import.meta.env.VITE_ENCRYPTION_KEY || 'js6w4nyx5ifkr2n7a3xi0o8p6q7g7ce9';
- export const encryptPassword = (password) => {
- if (!password) return "";
-
- try {
- const key = CryptoJS.enc.Utf8.parse(ENCRYPTION_KEY.substring(0, 32));
- const iv = CryptoJS.lib.WordArray.random(16);
- const encrypted = CryptoJS.AES.encrypt(password, key, {
- iv: iv,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7
- });
- const combined = iv.clone().concat(encrypted.ciphertext);
-
- return CryptoJS.enc.Base64.stringify(combined);
- } catch (error) {
- console.error("加密失败:", error);
- return password;
- }
- };
|