1 | var aes = require('./aes')
|
2 | var Transform = require('cipher-base')
|
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._update = function (chunk) {
|
21 | return this._mode.encrypt(this, chunk, this._decrypt)
|
22 | }
|
23 | StreamCipher.prototype._final = function () {
|
24 | this._cipher.scrub()
|
25 | }
|