UNPKG

761 BJavaScriptView Raw
1var aes = require('./aes');
2var Transform = require('./cipherBase');
3var inherits = require('inherits');
4
5inherits(StreamCipher, Transform);
6module.exports = StreamCipher;
7function StreamCipher(mode, key, iv, decrypt) {
8 if (!(this instanceof StreamCipher)) {
9 return new StreamCipher(mode, key, iv);
10 }
11 Transform.call(this);
12 this._cipher = new aes.AES(key);
13 this._prev = new Buffer(iv.length);
14 this._cache = new Buffer('');
15 this._secCache = new Buffer('');
16 this._decrypt = decrypt;
17 iv.copy(this._prev);
18 this._mode = mode;
19}
20StreamCipher.prototype._transform = function (chunk, _, next) {
21 next(null, this._mode.encrypt(this, chunk, this._decrypt));
22};
23StreamCipher.prototype._flush = function (next) {
24 this._cipher.scrub();
25 next();
26};
\No newline at end of file