Created
May 26, 2014 20:57
-
-
Save process/318b7d38a54368595d1e to your computer and use it in GitHub Desktop.
Creates an SSHA512 hash from the given cleartext and salt. If no salt is given, 4 random bytes are used. Derived from https://gist.github.com/itorres/2947088. The hashes generated by this function work with Dovecot, which is what is was written for.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ssha512(cleartext, salt) { | |
( typeof(salt) == 'undefined') ? salt = CryptoJS.lib.WordArray.random(4) : salt = CryptoJS.enc.Utf8.parse(salt); | |
var plain = CryptoJS.enc.Utf8.parse(cleartext); | |
var digest = CryptoJS.SHA512(plain.concat(salt)); | |
var ssha = '{SSHA512}' + digest.concat(salt).toString(CryptoJS.enc.Base64); | |
return ssha; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment