rfc:hash_pbkdf2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:hash_pbkdf2 [2012/07/02 16:32] – Open voting for hash_pbkdf2 ircmaxell | rfc:hash_pbkdf2 [2012/07/02 16:49] – Add 2 examples ircmaxell | ||
---|---|---|---|
Line 57: | Line 57: | ||
This parameter behaves just like the other *hash_* functions. If set to *true*, the function will return a binary string (chr 0-255). If set to *false*, the function will hex encode the result prior to returning it. | This parameter behaves just like the other *hash_* functions. If set to *true*, the function will return a binary string (chr 0-255). If set to *false*, the function will hex encode the result prior to returning it. | ||
+ | |||
+ | ===== Example ===== | ||
+ | |||
+ | Let's say you wanted to encrypt a file using a password. The password shouldn' | ||
+ | |||
+ | <file php encryption.php> | ||
+ | <?php | ||
+ | $password = " | ||
+ | $data = " | ||
+ | $salt = mcrypt_create_iv(16, | ||
+ | $key = hash_pbkdf2(" | ||
+ | // $key will be full-byte 0-255 data | ||
+ | |||
+ | $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, | ||
+ | |||
+ | $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | Or for storing passwords (BCrypt is recommended, | ||
+ | <file php password.php> | ||
+ | <?php | ||
+ | $password = " | ||
+ | $salt = mcrypt_create_iv(16, | ||
+ | $hash = hash_pbkdf2(" | ||
+ | |||
+ | // $hash will be a hex encoded string | ||
+ | ?> | ||
+ | </ | ||
+ | |||
===== Proposal and Patch ===== | ===== Proposal and Patch ===== |
rfc/hash_pbkdf2.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1