UNPKG

730 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._update = function (chunk) {
21 return this._mode.encrypt(this, chunk, this._decrypt);
22};
23StreamCipher.prototype._final = function () {
24 this._cipher.scrub();
25};
\No newline at end of file