dongwei7245 2010-07-29 17:22
浏览 238
已采纳

php openssl使用aes256加密数据并使用sha256散列传递帮助!

openssl only accepting half of a sha256 hashed password
$encryptedkey = openssl_encrypt ($data, 'AES256', "$sha256", $raw_output = false);
hash looks like this:a0461cea77b9942addee32b2265b32ebcf150426e2490810938ab47206fd320b
its only accepting 32 characters of it:a0461cea77b9942addee32b2265b32eb
how can i fix this? thank you!

edit: example: when decrypting the data if the hash does not mach after 32 character it will still decrypt it even if its wrong

a0461cea77b9942addee32b2265b32ebcf150426e2490810938ab47206fd320b
a0461cea77b9942addee32b2265b32ebcf150426e24808019485b43406df3a9b

both will work when they shouldn't?

  • 写回答

1条回答 默认 最新

  • donglaohua1671 2010-07-29 17:31
    关注

    I'd guess you should pass the raw data, not an hexadecimal representation of it. I say this because 32*8=256, hence by reading 32 characters, the function is actually reading 256 bits.

    Try passing pack("H*", $sha256) instead of $sha256.

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

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler