本文介绍了解密 Node.js 中使用 OpenSSL 加密的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下命令在 openssl 中加密视频文件
I'm using the following command to encrypt a video file in openssl
openssl aes-256-cbc -nosalt -a -in movie.mp4 -out movie.enc -k skdjfsldkfjsldkjfsldkf
并使用以下代码解密文件,但我不断收到错误的解密错误,我做错了什么?
And using the following code to decrypt the file but I keep getting bad decrypt error what am I doing wrong?
var crypto = require('crypto');
var fs = require('fs');
cipher_name = 'aes-256-cbc';
password = 'skdjfsldkfjsldkjfsldkf';
decoder = crypto.createDecipher( cipher_name, password );
text_crypt = fs.readFileSync( 'movie.enc' );
chunks = [];
chunks.push(decoder.update( text_crypt, 'binary' ));
chunks.push(decoder.final( 'binary' ));
fs.writeFileSync( 'nodemovie.mp4',chunks.join('','binary') );
这是我得到的错误
Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Decipher.final (crypto.js:160:26)
at Object.<anonymous> (F:\java\index.js:12:21)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
我应该能够在openssl中加密视频并同时在node和java中解密
I should be able to encrypt video in openssl and decrypt in node and java at the same time
推荐答案
正如 jww 所说,openssl -k
和 -K
是不一样的.
as jww said, openssl -k
and -K
are not the same.
openssl aes-256-cbc -nosalt -in movie.mp4 -out movie.enc -k skdjfsldkfjsldkjfsldkf -p
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
key=ED67064595132E4F1154C557A3C103999CF719B66855B6563C6B35D346CDE40E
iv =4FB8711CAD9659FF2F1DCE33A7D3E0B7
知道key
和iv
var crypto = require('crypto');
var fs = require('fs');
cipher_name = 'aes-256-cbc';
//password = 'skdjfsldkfjsldkjfsldkf';
//decoder = crypto.createDecipher( cipher_name, password );
iv = Buffer.from('4FB8711CAD9659FF2F1DCE33A7D3E0B7','hex');
key = Buffer.from('ED67064595132E4F1154C557A3C103999CF719B66855B6563C6B35D346CDE40E','hex');
decoder = crypto.createDecipheriv( cipher_name, key, iv );
text_crypt = fs.readFileSync( 'movie.enc' );
chunks = [];
chunks.push(decoder.update( text_crypt, 'binary' ));
chunks.push(decoder.final( 'binary' ));
fs.writeFileSync( 'nodemovie.mp4',chunks.join('','binary') );
这篇关于解密 Node.js 中使用 OpenSSL 加密的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!