Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created December 7, 2011 23:46
Show Gist options
  • Save rockpapergoat/1445340 to your computer and use it in GitHub Desktop.
Save rockpapergoat/1445340 to your computer and use it in GitHub Desktop.
#!/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