我对Node非常陌生,并且遇到了加密对象的问题:
var des3_key = new Buffer("redacted", "base64"); // copied from key in chilk
var des3_iv = new Buffer("alsoredacted", "base64"); // copied from iv in chilk
var des3_encryption = crypto.createCipheriv("des3", des3_key, des3_iv);
// encode a string
var string_to_encode = "thisisatest";
var ciphered_string = des3_encryption.update(string_to_encode, "utf8", "base64");
console.log(string_to_encode+" "+ciphered_string);无论是在节点控制台中还是在服务器上运行时,第6行都会导致错误node-crypto: Invalid IV length 32,而不是像预期的那样返回加密对象。
我删除的密钥和IV以及它们的加密类型是从另一个文件复制的,但是为了测试,我尝试了各种字符串和加密类型,但仍然得到了相同的错误,尽管错误中的长度不同。
不幸的是,我对加密的了解仅限于我以前使用过的内容,而且很难找到Node在这方面的故障排除资源。任何帮助都将不胜感激。
编辑:使用des和des3进行实验会产生同样的结果。
发布于 2015-12-01 16:22:45
来自OP的编辑:
已解决:
工作代码:
var string_to_decode = "encrypted string";
var des_key = new Buffer("key string", "base64");
var des_iv = new Buffer(0);
var des_decryption = Crypto.createDecipheriv("DES-EDE3", des_key, des_iv);
var deciphered_string = des_decryption.update(string_to_decode, "base64", "utf8");
console.log("["+string_to_decode+"] => ["+deciphered_string+"]");我通过编写一个脚本来猜测密钥和IV长度的组合、加密类型和方法以及编码类型,直到得到正确的字符串为止,我发现了这一点。这是最后的手段,但成功了。
https://stackoverflow.com/questions/24384394
复制相似问题