Sha256: 4113d6c7a3eecb19d461c1b7c2842273308eab0a5eda20e080a16f271cc84a30

Contents?: true

Size: 1.17 KB

Versions: 30

Compression:

Stored size: 1.17 KB

Contents

var CipherBase = require('cipher-base')
var des = require('des.js')
var inherits = require('inherits')
var Buffer = require('safe-buffer').Buffer

var modes = {
  'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  'des-ede3': des.EDE,
  'des-ede-cbc': des.CBC.instantiate(des.EDE),
  'des-ede': des.EDE,
  'des-cbc': des.CBC.instantiate(des.DES),
  'des-ecb': des.DES
}
modes.des = modes['des-cbc']
modes.des3 = modes['des-ede3-cbc']
module.exports = DES
inherits(DES, CipherBase)
function DES (opts) {
  CipherBase.call(this)
  var modeName = opts.mode.toLowerCase()
  var mode = modes[modeName]
  var type
  if (opts.decrypt) {
    type = 'decrypt'
  } else {
    type = 'encrypt'
  }
  var key = opts.key
  if (!Buffer.isBuffer(key)) {
    key = Buffer.from(key)
  }
  if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
    key = Buffer.concat([key, key.slice(0, 8)])
  }
  var iv = opts.iv
  if (!Buffer.isBuffer(iv)) {
    iv = Buffer.from(iv)
  }
  this._des = mode.create({
    key: key,
    iv: iv,
    type: type
  })
}
DES.prototype._update = function (data) {
  return Buffer.from(this._des.update(data))
}
DES.prototype._final = function () {
  return Buffer.from(this._des.final())
}

Version data entries

30 entries across 29 versions & 10 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/browserify-des/index.js
disco_app-0.18.0 test/dummy/node_modules/browserify-des/index.js
disco_app-0.18.2 test/dummy/node_modules/browserify-des/index.js
disco_app-0.16.1 test/dummy/node_modules/browserify-des/index.js
disco_app-0.15.2 test/dummy/node_modules/browserify-des/index.js
disco_app-0.18.4 test/dummy/node_modules/browserify-des/index.js
disco_app-0.18.1 test/dummy/node_modules/browserify-des/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/browserify-des/index.js
disco_app-0.14.0 test/dummy/node_modules/browserify-des/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/browserify-des/index.js
tang-0.2.1 spec/tang_app/node_modules/browserify-des/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/browserify-des/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/browserify-des/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/browserify-des/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/browserify-des/index.js
tang-0.2.0 spec/tang_app/node_modules/browserify-des/index.js
tang-0.1.0 spec/tang_app/node_modules/browserify-des/index.js
tang-0.0.9 spec/tang_app/node_modules/browserify-des/index.js
enju_library-0.3.8 spec/dummy/node_modules/browserify-des/index.js
ilog-0.4.1 node_modules/browserify-des/index.js