Created
February 3, 2015 11:32
-
-
Save nicksnell/43efad2e93b8d1f4de53 to your computer and use it in GitHub Desktop.
Password hashing with pbkdf2 hmac, expected output is: 2258da2b7b0bf789df92dd56bec9eeda3b42d5e9cfe7ea311ed01c84f7cd2734
This file contains hidden or 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
| <?php | |
| $hash = hash_pbkdf2('sha256', 'example', 'some salt', 100000); | |
| echo $hash; | |
| ?> |
This file contains hidden or 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 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" |
This file contains hidden or 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
| 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')) |
This file contains hidden or 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
| 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