Closed zhuijing closed 4 years ago
刚解出来,需要联系我300块钱,6行代码,不需要第三方库。
已经解决,谢谢。 var crypto = require('crypto'); var data = "4m4HcVZR14pvTtmNbqgkH3qtmLhJpCZx6oi6u2stmGUo2Z3OmKhtHF/VaiFQ023pKJvhXwSRVjC3IBaotOduxO/zIrIqfg+xnvBWY2zYC/UDLPbsm66yz8omvQLRBGsP8MHYLaOFEgFUgREOCa8AKH7u9v6YlnTIdp1XZGGZnKydissMwTiU4xrM5quZnFwqgTSXmCzSEfeHfjr4qTO+pLGRfY/0J/U932FCq012udkj0pA1UspfCnUU4LY8z3AiPr63TKS4ZEj5Pxz5x7beTf5pGQDrrFHaB87/dbbo8V/143RalmWsyNTiKlAA6S8OO4uXtL6tkYXCddyYQnk6waYqrZOgJLnVS5o9PLzzChU=" // 支付小程序配置 var aes = 'Lj59Ubk1ZyzlUZGTKgTl6A=='; var aeskey = Buffer.from(aes, 'base64'); var iv = aeskey;
var iv = Buffer.alloc(aeskey.length, '\0');
var crypted = Buffer.from(data, 'base64');
var decipher = crypto.createDecipheriv('aes-128-cbc', aeskey, iv); var decoded = decipher.update(crypted,'base64','utf8'); decoded += decipher.final('utf8'); console.log('decoded :', decoded);
` var CryptoJS = require("crypto-js"); // 用户在支付宝小程序授权手机号后的 response var data = "" // 支付宝小程序设置的 AES var aes = 'Lj59Ubk1ZyzlUZGTKgTl6A=='; // Base64 Utf8 var res = Buffer.from(data,'base64').toString(); console.log(res,'res') var aes1 = Buffer.from(aes,'base64').toString(); console.log(aes1,'aes1')
var bytes = CryptoJS.AES.decrypt(res, aes1);
var plaintext = bytes.toString(CryptoJS.enc.Utf8); console.log(plaintext,'plaintext'); `
这是我写的,但是不对。请问怎么改呢?