admin管理员组文章数量:1340302
nodejs与php混合,node.js
nodejs的加密解密代码示例如下:#!/usr/bin/env node
var crypto = require('crypto');
//解密
function decode(cryptkey, iv, secretdata) {
var
decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
decoded = decipher.update(secretdata, 'base64', 'utf8');
decoded += decipher.final( 'utf8' );
return decoded;
}
//解密
function encode(cryptkey, iv, cleardata) {
var
encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
encoded = encipher.update(cleardata, 'utf8', 'base64');
encoded += encipher.final( 'base64' );
return encoded;
}
var
cryptkey = crypto.createHash('sha256').update('__tazai_wolf__key').digest(),
iv = '1234567890000000',
buf = "Hello World",
enc = encode( cryptkey, iv, buf );
var dec = decode(cryptkey, iv, enc);
function b64enc(data) {
var b = new Buffer(data, 'binary');
return b.toString('base64');
}
console.warn("Encoded length: ", enc);
console.warn("Decoded all: " + dec);
请问php能相应的加密解密代码应该如何写?
要求能解上面加密后的如:Gpkr1WGBFhMvNd/Hr0eaBg==
也能加密数据给nodejs进行解密。
回复内容:
nodejs的加密解密代码示例如下:#!/usr/bin/env node
var crypto = require('crypto');
//解密
function decode(cryptkey, iv, secretdata) {
var
decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
decoded = decipher.update(secretdata, 'base64', 'utf8');
decoded += decipher.final( 'utf8' );
return decoded;
}
//解密
function encode(cryptkey, iv, cleardata) {
var
encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
encoded = encipher.update(cleardata, 'utf8', 'base64');
encoded += encipher.final( 'base64' );
return encoded;
}
var
cryptkey = crypto.createHash('sha256').update('__tazai_wolf__key').digest(),
iv = '1234567890000000',
buf = "Hello World",
enc = encode( cryptkey, iv, buf );
var dec = decode(cryptkey, iv, enc);
function b64enc(data) {
var b = new Buffer(data, 'binary');
return b.toString('base64');
}
console.warn("Encoded length: ", enc);
console.warn("Decoded all: " + dec);
请问php能相应的加密解密代码应该如何写?
要求能解上面加密后的如:Gpkr1WGBFhMvNd/Hr0eaBg==
也能加密数据给nodejs进行解密。
本文原创发布php中文网,转载请注明出处,感谢您的尊重!
本文标签: nodejs与php混合nodejs
版权声明:本文标题:nodejs与php混合,node.js 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1701489004a416815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论