doujiao0110 2014-03-12 07:22
浏览 21

php crypt - 尾随美元符号 - 仅从哈希中提取盐部分 - 填充盐

I am reading up on PHP's crypt() function. I have a few questions on it -

  1. What is the significance of the trailing '$' sign at the end of the salt string that I see in most examples. The manual doesn't specifically say anything about ending the salt string with it.

  2. Is there anyway I can extract only the salt portion from the hash? I know that I probably don't need to, since the crypt() function will internally do it when doing a comparison. But just for the heck of it. Just for me to see the salt. For egs consider this code -

    $pass = 'secret'; $salt = '$2y$07$usesomesillystringforsalt$'; echo crypt($pass, $salt);

    The output of this is $2y$07$usesomesillystringforex.u2VJUMLRWaJNuw0Hu2FvCEimdeYVO and I am unsure about the boundary between the salt and the hash. Is the 'e' in the 'forex' sub string part of the salt or the hash? It would be much easier if I could just extract the salt part of it.

  3. Also the crypt() manual says

    ... Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z"....

    As per this I expect 22 characters after the $ sign following the cost parameter. But consider this code -

    $pass = 'secret'; $salt = '$2y$07$somesillystring$'; echo crypt($pass, $salt);

    The output of this is $2y$07$somesillystring$$$$$$.O6JLPmGlDvy4BicGmkuBD.DN8OYiIoG. My question is why is it padded only up to 21 characters following the $ sign after the cost parameter. I was expecting it to be padded up to 22 characters.

  • 写回答

2条回答 默认 最新

  • dongmu5596 2014-03-12 07:40
    关注
    1. Some crypt() algorithms separate the salt from the crypt with a dollar sign. Blowfish doesn't.

    2. PHP provides no facility for just extracting the salt. You would need an associative array of algorithms and salt positions/lengths.

    3. I'm not sure why the 21 vs 22 character difference. Could it be an error in the PHP manual? Try running "man crypt" or go to http://linux.die.net/man/3/crypt .

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计