工具型应用订购对接流程–订购消息解密
export class DouyinUtils {
private readonly crypto = require('crypto');
/**
* 订购对接流程消息解密
* @param msg
* @param appSecret
*/
public decryptMsg(msg: string, appSecret: string) {
const secret = appSecret.replace(/-/g, '');
let cipherChunks = [];
console.log(secret)
const decipher = this.crypto.createDecipheriv('aes-256-cbc', secret, secret.substring(0, 16));
decipher.setAutoPadding(true);
cipherChunks.push(decipher.update(msg, 'base64', 'utf8'));
cipherChunks.push(decipher.final('utf8'));
const result = JSON.parse(cipherChunks.join(''));
result.msg = JSON.parse(result.msg);
return result;
}
}