mirror of
https://github.com/wu736139669/Monkey-Test.git
synced 2026-08-05 05:55:46 +00:00
26 lines
761 B
JavaScript
26 lines
761 B
JavaScript
var aes = require('./aes');
|
|
var Transform = require('./cipherBase');
|
|
var inherits = require('inherits');
|
|
|
|
inherits(StreamCipher, Transform);
|
|
module.exports = StreamCipher;
|
|
function StreamCipher(mode, key, iv, decrypt) {
|
|
if (!(this instanceof StreamCipher)) {
|
|
return new StreamCipher(mode, key, iv);
|
|
}
|
|
Transform.call(this);
|
|
this._cipher = new aes.AES(key);
|
|
this._prev = new Buffer(iv.length);
|
|
this._cache = new Buffer('');
|
|
this._secCache = new Buffer('');
|
|
this._decrypt = decrypt;
|
|
iv.copy(this._prev);
|
|
this._mode = mode;
|
|
}
|
|
StreamCipher.prototype._transform = function (chunk, _, next) {
|
|
next(null, this._mode.encrypt(this, chunk, this._decrypt));
|
|
};
|
|
StreamCipher.prototype._flush = function (next) {
|
|
this._cipher.scrub();
|
|
next();
|
|
}; |