Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (31 sloc) 0.939 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# Description:
# Various hashing algorithms.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot md5|sha|sha1|sha256|sha512|rmd160 me <string> - Generate hash of <string>
#
# Author:
# jimeh

crypto = require 'crypto'

module.exports = (robot) ->
  robot.respond /md5( me)? (.*)/i, (msg) ->
    msg.send hexDigest(msg.match[2], 'md5')

  robot.respond /SHA( me)? (.*)/i, (msg) ->
    msg.send hexDigest(msg.match[2], 'sha')

  robot.respond /SHA1( me)? (.*)/i, (msg) ->
    msg.send hexDigest(msg.match[2], 'sha1')

  robot.respond /SHA256( me)? (.*)/i, (msg) ->
    msg.send hexDigest(msg.match[2], 'sha256')

  robot.respond /SHA512( me)? (.*)/i, (msg) ->
    msg.send hexDigest(msg.match[2], 'sha512')

  robot.respond /RMD160( me)? (.*)/i, (msg) ->
    msg.send hexDigest(msg.match[2], 'rmd160')

# hex digest helper
hexDigest = (str, algo) ->
  crypto.createHash(algo).update(str, 'utf8').digest('hex')
Something went wrong with that request. Please try again.