Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

How to hash & salt in various languages.

Gioyik edited this page Nov 12, 2012 · 3 revisions

PHP

<?php
function hashEmailAddress($email, $salt) {
  return 'sha256$' . hash('sha256', $email . $salt);
}
?>

Ruby

require 'digest'
def hashEmailAddress(email, salt)
  'sha256$' + Digest::SHA256.hexdigest(email + salt)
end

Python

import hashlib
def hashEmailAddress(email, salt):
    return 'sha256$' + hashlib.sha256(email + salt).hexdigest();
#!/usr/bin/python
import hashlib
email = raw_input('Email address? ')
salt = '#ioe12'
hash = hashlib.sha256(email + salt)
print (salt.encode('hex'), hash.hexdigest())

Node.js

var crypto = require('crypto');
function hashEmailAddress(email, salt) {
  var sum = crypto.createHash('sha256');
  sum.update(email + salt);
  return 'sha256$'+ sum.digest('hex');
}
Clone this wiki locally