Skip to content

Instantly share code, notes, and snippets.

@nicksnell
Created February 3, 2015 11:32
Show Gist options
  • Select an option

  • Save nicksnell/43efad2e93b8d1f4de53 to your computer and use it in GitHub Desktop.

Select an option

Save nicksnell/43efad2e93b8d1f4de53 to your computer and use it in GitHub Desktop.
Password hashing with pbkdf2 hmac, expected output is: 2258da2b7b0bf789df92dd56bec9eeda3b42d5e9cfe7ea311ed01c84f7cd2734
<?php
$hash = hash_pbkdf2('sha256', 'example', 'some salt', 100000);
echo $hash;
?>
#!/usr/bin/env perl
use Crypt::PBKDF2;
my $password = 'example';
my $salt = 'some salt';
my $pbkdf2 = Crypt::PBKDF2->new(
hash_class => 'HMACSHA2',
iterations => 100000,
);
my $hash = $pbkdf2->PBKDF2_hex($salt, $password);
print $hash, "\n"
import binascii
import hashlib
def encrypt_password(password, salt):
dk = hashlib.pbkdf2_hmac(
'sha256',
str(password).encode('utf8'),
str(salt).encode('utf8'),
100000
)
return str(binascii.hexlify(dk))
print(encrypt_password('example', 'some salt'))
require 'openssl'
def encrypt_password(password, salt)
digest = OpenSSL::Digest::SHA256.new
value = OpenSSL::PKCS5.pbkdf2_hmac(
password,
salt,
100000,
digest.digest_length,
digest
)
value.split("").collect {|c| c[0].to_s(16)}.join
end
puts encrypt_password('example', 'some salt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment