php - AES-256-CBC 加密 Node.Js 但无法在 PHP 中解密
问题描述
我正在尝试使用 aes-256-cbc 加密对象数组,但它没有发生:
let key = new Buffer(SSO_key, 'base64');//decoding key in base64
let IV = new Buffer(SSO_IV, 'base64');//decoding IV in base64
Text.push({
pdf_text: get_content,//getting encrypted pdf here
course_id: "123",
candidate_id: "123",
time_stamp: new Date()
})
Text = Buffer.from(JSON.stringify(Text));
let cipher1 = crypto.createCipheriv('aes-256-cbc', key, IV);
let get_content1 = cipher1.update(Text, 'utf8', 'base64') + cipher1.final('base64');
解决方案
只要SSO_key
, 当编码base64
为 32 字节长并且SSO_IV
, 当编码base64
为 16 字节长时,您的代码应该可以工作。
我尝试了下面的代码,它与您拥有的代码尽可能接近:
const crypto = require('crypto');
let key = Buffer.alloc(32, 0); //new Buffer("asdakjdsh", 'base64');//decoding key in base64
let IV = Buffer.alloc(16, 0);
let Text = [];
Text.push({
pdf_text: "get_content",//getting encrypted pdf here
course_id: "123",
candidate_id: "123",
time_stamp: new Date()
})
Text = Buffer.from(JSON.stringify(Text));
let cipher1 = crypto.createCipheriv('aes-256-cbc', key, IV);
let get_content1 = cipher1.update(Text, 'utf8', 'hex') + cipher1.final('hex');
console.log(`==========getcontent`, get_content1);
输出是:
==========getcontent 367bbed3d629faa8baaad6f9116277006b9b6b8fa80226e04d1bcdbda444b63054dc6250cb1920604988a48b6508dd96b2ec08382921146a71e914aa9e94f2a14fa598ee4aeda064e15020a7791b1e4db513b94f59d7df19d612c66616683075a1d7a7e8f66a2d341c0a234d2c3b4cea
推荐阅读
- powershell - 奇怪的字符串问题
- android - ImageLoader 在使用前必须先进行配置
- java - 在android中同时拨打多个号码
- c# - 如何在表单和页面之间传递变量
- jquery - 如何在 JtaCarousel Jquery 中更改滑动时间(自动播放)?
- python - django 和 uwsgi + nginx 中的内部服务器错误
- java - 使用 java 获取客户端系统名称
- shell - Shell - 我怎样才能让 Logrotate 等到文件被复制/写入然后继续
- rdf - Jena DataAccessorFactory 与议会三联存储?
- javascript - Slick Slider - 如何保持活动分页(点)始终居中