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

Function AESencrypt

utils/EncryUtils.js:49–66  ·  view source on GitHub ↗

* AES 加密 * @param {string} data - * @param {string} baseKey - * @param {string} ivStr - * @returns {string} -

(data, baseKey = KEY_AES, ivStr = IV)

Source from the content-addressed store, hash-verified

47 * @returns {string} -
48 */
49function AESencrypt(data, baseKey = KEY_AES, ivStr = IV) {
50 let key = Buffer.from(baseKey, "utf8")
51 let iv = Buffer.from(ivStr, "utf8")
52
53 // 填充长度
54 if (key.length < 32) {
55 const paddedKey = Buffer.alloc(32);
56 key.copy(paddedKey);
57 key = paddedKey;
58 }
59 if (iv.length < 16) {
60 const paddedIV = Buffer.alloc(16);
61 iv.copy(paddedIV);
62 iv = paddedIV;
63 } const cipher = crypto.createCipheriv("aes-256-cbc", key, iv)
64 const dest = cipher.update(data, "utf8", "base64") + cipher.final("base64")
65 return dest.toString()
66}
67
68/**
69 * AES 解密

Callers 1

refreshTokenFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected