1
|
var aes = require('./aes')
|
2
|
var Buffer = require('safe-buffer').Buffer
|
3
|
var Transform = require('cipher-base')
|
4
|
var inherits = require('inherits')
|
5
|
|
6
|
function StreamCipher (mode, key, iv, decrypt) {
|
7
|
Transform.call(this)
|
8
|
|
9
|
this._cipher = new aes.AES(key)
|
10
|
this._prev = Buffer.from(iv)
|
11
|
this._cache = Buffer.allocUnsafe(0)
|
12
|
this._secCache = Buffer.allocUnsafe(0)
|
13
|
this._decrypt = decrypt
|
14
|
this._mode = mode
|
15
|
}
|
16
|
|
17
|
inherits(StreamCipher, Transform)
|
18
|
|
19
|
StreamCipher.prototype._update = function (chunk) {
|
20
|
return this._mode.encrypt(this, chunk, this._decrypt)
|
21
|
}
|
22
|
|
23
|
StreamCipher.prototype._final = function () {
|
24
|
this._cipher.scrub()
|
25
|
}
|
26
|
|
27
|
module.exports = StreamCipher
|