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.

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

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算