Created
December 7, 2011 23:46
-
-
Save rockpapergoat/1445340 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'digest/sha2' | |
require 'cfpropertylist' | |
def salted_sha512(password) | |
seedint = rand(((2**31 - 1)-1+1)) | |
seedhex = ("%x" % seedint).upcase.rjust(8, '0') | |
seedstring = seedint.to_a.pack("L") | |
saltedpass = Digest::SHA512.hexdigest(seedstring + password) | |
saltedhash = {'ShadowHashData' => (seedstring + saltedpass)}.to_a.flatten | |
return saltedhash.to_a.flatten | |
end | |
password_hash = salted_sha512("password") | |
plist = CFPropertyList::List.new | |
plist.value = CFPropertyList::CFData.new(value=password_hash[1],format="DATA_RAW") | |
plist.save("password.plist", CFPropertyList::List::FORMAT_BINARY) | |
=begin | |
python version of this from createuser_lion hash generation script | |
def salted_sha512(password): | |
seedInt = random.randrange(1, 2**31 - 1) | |
seedHex = ("%x" % seedInt).upper().zfill(8) | |
seedString = struct.pack(">L", seedInt) | |
saltedPassword = hashlib.sha512(seedString + password).digest() | |
return "%s%s" % (seedString, saltedPassword) | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment