1 | var aes = require('./aes');
|
2 | var Transform = require('./cipherBase');
|
3 | var inherits = require('inherits');
|
4 |
|
5 | inherits(StreamCipher, Transform);
|
6 | module.exports = StreamCipher;
|
7 | function 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 | }
|
20 | StreamCipher.prototype._transform = function (chunk, _, next) {
|
21 | next(null, this._mode.encrypt(this, chunk, this._decrypt));
|
22 | };
|
23 | StreamCipher.prototype._flush = function (next) {
|
24 | this._cipher.scrub();
|
25 | next();
|
26 | }; |
\ | No newline at end of file |