browser.js 625 B

123456789101112131415161718192021222324252627282930
  1. 'use strict'
  2. var inherits = require('inherits')
  3. var MD5 = require('md5.js')
  4. var RIPEMD160 = require('ripemd160')
  5. var sha = require('sha.js')
  6. var Base = require('cipher-base')
  7. function Hash (hash) {
  8. Base.call(this, 'digest')
  9. this._hash = hash
  10. }
  11. inherits(Hash, Base)
  12. Hash.prototype._update = function (data) {
  13. this._hash.update(data)
  14. }
  15. Hash.prototype._final = function () {
  16. return this._hash.digest()
  17. }
  18. module.exports = function createHash (alg) {
  19. alg = alg.toLowerCase()
  20. if (alg === 'md5') return new MD5()
  21. if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()
  22. return new Hash(sha(alg))
  23. }