乐享知识库接口文档 当开放接口下载的文件内容需要解密时,请参考以下资料:
AES-256-CBC⚠️ 重要:加密不仅仅是为了解决网络传输过程被窃取(接口本来就是https加密传输),也是防止调用方拉取文件后,使用完毕没有及时清理,存储于云端等,若没有加密,容易造成通讯录敏感信息泄漏。
建议调用方使用固定的32位字符串,不需要每次请求生成新的。
download_url 下载加密文件(内容为 Base64 编码)aeskey,IV 为密钥前16字节)<?php
$aesKey = "today+yesterday+tomorrow+1234567"; // 32位
$content = file_get_contents("./成员导出.json");
if (!empty($content)) {
// Base64 解码
$encrypted = base64_decode($content);
// AES 解密
$iv = substr($aesKey, 0, 16);
$decrypted = \openssl_decrypt($encrypted, 'AES-256-CBC', $aesKey, OPENSSL_RAW_DATA, $iv);
echo $decrypted;
}
?>
import base64
import json
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
# 32位 AES 密钥(与创建任务时传入的 aeskey 相同)
aes_key = "today+yesterday+tomorrow+1234567"
# 读取下载的加密文件
with open("成员导出.json", "r") as f:
base64_data = f.read().strip()
# 1. Base64 解码
encrypted_data = base64.b64decode(base64_data)
# 2. AES-256-CBC 解密
iv = aes_key[:16].encode('utf-8') # IV 为密钥前16字节
key = aes_key.encode('utf-8')
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted_data = unpad(cipher.decrypt(encrypted_data), AES.block_size)
# 3. 解析 JSON
members = json.loads(decrypted_data.decode('utf-8'))
print(f"成员总数: {len(members)}")
const crypto = require('crypto');
const fs = require('fs');
// 32位 AES 密钥
const aesKey = 'today+yesterday+tomorrow+1234567';
// 读取下载的加密文件
const base64Data = fs.readFileSync('./成员导出.json', 'utf8').trim();
// 1. Base64 解码
const encryptedData = Buffer.from(base64Data, 'base64');
// 2. AES-256-CBC 解密
const iv = Buffer.from(aesKey.substring(0, 16), 'utf8');
const decipher = crypto.createDecipheriv('aes-256-cbc', aesKey, iv);
let decrypted = decipher.update(encryptedData);
decrypted = Buffer.concat([decrypted, decipher.final()]);
// 3. 解析 JSON
const members = JSON.parse(decrypted.toString('utf8'));
console.log(`成员总数: ${members.length}`);
Q: 解密时报错 "Padding is incorrect" 或 "Invalid padding"?
A: 请检查:
aeskey 一致Q: 下载的文件内容是什么格式?
A: 下载的文件内容是 Base64 编码的字符串,需要先进行 Base64 解码,再进行 AES 解密。
← 查询任务