MCPcopy Create free account
hub / github.com/develop202/migu_video / AESdecrypt

Function AESdecrypt

utils/EncryUtils.js:75–93  ·  view source on GitHub ↗

* AES 解密 * @param {string} baseData - * @param {string} baseKey - * @param {string} ivStr - * @returns {string} -

(baseData, baseKey = KEY_AES, ivStr = IV)

Source from the content-addressed store, hash-verified

73 * @returns {string} -
74 */
75function 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/**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected