2016-12-20 6 views
0

このURLの暗号化の例(以下のコードサンプル)(http://lollyrock.com/articles/nodejs-encryption/)に従っています。問題は、私が.zipファイルを暗号化していることです。これは正常に動作するようです。解読が問題です。以下のコード例をjpgのようなもので実行すると、画像がうまく出てきます。しかし、私はそれを介してzipファイルを実行すると、私はunzipに結果をしようと、私は次のエラーを取得する:zipファイルを含むNodeJS暗号パッケージ

End-of-central-directory signature not found. Either this file is not 
    a zipfile, or it constitutes one disk of a multi-part archive. In the 
    latter case the central directory and zipfile comment will be found on 
    the last disk(s) of this archive. 

コード:

// Nodejs encryption of buffers 
var crypto = require('crypto'), 
    algorithm = 'aes-256-ctr', 
    password = 'd6F3Efeq'; 

var fs = require('fs'); 
var zlib = require('zlib'); 

// input file 
var r = fs.createReadStream('file.txt'); 
// zip content 
var zip = zlib.createGzip(); 
// encrypt content 
var encrypt = crypto.createCipher(algorithm, password); 
// decrypt content 
var decrypt = crypto.createDecipher(algorithm, password) 
// unzip content 
var unzip = zlib.createGunzip(); 
// write file 
var w = fs.createWriteStream('file.out.txt'); 

// start pipe 
r.pipe(zip).pipe(encrypt).pipe(decrypt).pipe(unzip).pipe(w); 

答えて

0

だから、私のコードの違いはそれだっ判明しますリクエストストリームから読み込み中です。どうやら、復号化によってgunzipを通して要求ストリームをパイプするだけではどうですか?なぜ私は分からない。

しかし、ストリームをファイルと同じにしてからgunzipと復号化を実行すると、それが動作します。

誰かが理由を入力した場合、私は少なくとも理解したいと思います!

関連する問題