Skip to content

Instantly share code, notes, and snippets.

@Zenithar
Created July 24, 2012 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zenithar/3169823 to your computer and use it in GitHub Desktop.
Save Zenithar/3169823 to your computer and use it in GitHub Desktop.
Hashing algorithm conform to Owasp.
crypto = require("crypto")
#
# Hashing algorithm conform to Owasp.
# https://www.owasp.org/index.php/Hashing_Java
#
exports.secureHash = (algorithm, key, message, iterations) ->
hash = crypto.createHash(algorithm)
hmac = crypto.createHmac(algorithm, key)
buf = hash.update(key).digest() + message
i = 0
while i < iterations - 1
buf = hmac.update(buf).digest()
hmac = crypto.createHmac(algorithm, key)
i++
hmac = crypto.createHmac(algorithm, key)
hmac.update(buf).digest "base64"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment