Hashing in SHA512 using a salt? - Python

RadiantHex picture RadiantHex · May 24, 2010 · Viewed 65.8k times · Source

I have been looking through ths hashlib documentation but haven't found anything talking about using salt when hashing data.

Help would be great.

Answer

Rakis picture Rakis · May 24, 2010

Samir's answer is correct but somewhat cryptic. Basically, the salt is just a randomly derived bit of data that you prefix or postfix your data with to dramatically increase the complexity of a dictionary attack on your hashed value. So given a salt s and data d you'd just do the following to generate a salted hash of the data:

import hashlib
hashlib.sha512( s + d ).hexdigest()

See this wikipedia article for more details