doushai7225 2016-10-04 06:12
浏览 33
已采纳

生成/存储/读取安全MCRYPT盐

I know this may be somewhat a common question, there are SO many articles across the net about generating secure salts for password hashing. So far I've picked up the mcrypt_create_iv is generally used for initialisation vectors for encryption, it can be used to create salt securely especially when used against MCRYPT_DEV_RANDOM.

For some reason despite people having success with it, whenever I use:

$Salt = mcrypt_create_iv(22, MCRYPT_DEV_RANDOM);

Apply it to the hash, then separately input it into the db. When coming back and authenticating and putting it all together... it never seems to work correctly.

Are there some characters that are generated by the mcrypt_create_iv function that aren't compatible with crypt? Because the second I use a somewhat plaintext salt whether generated from a secure source or not.. it works fine. But I would like to make use of the special characters mcrypt uses.

(Also, I am using the $6$ algorithm on crypt so only 16 bytes required for the salt)

Any help would be appreciated!

Thanks :)

  • 写回答

1条回答 默认 最新

  • dpndp64206 2016-10-04 06:20
    关注

    I recommend using the password_hash() family of functions, as these will take care of the hashing for you completely. They also offer future-compatibility, and is generally the recommended method for handling passwords in PHP.

    Read more about how to use them in this answer: https://stackoverflow.com/a/6337021/5086233

    As for your original question: I suspect a charset issue somewhere, but without seeing the code (and table definition) that handles the hash it's impossible to tell.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?