選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

streamCipher.js 659B

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