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

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
    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.

    点赞 评论

相关推荐