* AES 解密 * @param {string} baseData - * @param {string} baseKey - * @param {string} ivStr - * @returns {string} -
(baseData, baseKey = KEY_AES, ivStr = IV)
| 73 | * @returns {string} - |
| 74 | */ |
| 75 | function AESdecrypt(baseData, baseKey = KEY_AES, ivStr = IV) { |
| 76 | let key = Buffer.from(baseKey, "utf8") |
| 77 | let iv = Buffer.from(ivStr, "utf8") |
| 78 | |
| 79 | // 填充长度 |
| 80 | if (key.length < 32) { |
| 81 | const paddedKey = Buffer.alloc(32); |
| 82 | key.copy(paddedKey); |
| 83 | key = paddedKey; |
| 84 | } if (iv.length < 16) { |
| 85 | const paddedIV = Buffer.alloc(16); |
| 86 | iv.copy(paddedIV); |
| 87 | iv = paddedIV; |
| 88 | } |
| 89 | const data = Buffer.from(baseData, "utf8") |
| 90 | const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv) |
| 91 | const dest = Buffer.concat([decipher.update(data), decipher.final()]) |
| 92 | return dest.toString() |
| 93 | } |
| 94 | |
| 95 | |
| 96 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected