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?
views:
145answers:
1
A:
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
.
Artefacto
2010-07-29 17:31:25
Is that a secure what of converting it?<br>this is what it did to the hash: "‚•É+3�6B™Ó¤R- Kai%¡þÊnª
cryptscript
2010-07-29 17:55:52
@user Sure, that's just the raw representation. You can see that e.g. `pack("H*", hash("sha256", "mydata")) == hash("sha256", "mydata", true)`.
Artefacto
2010-07-29 18:03:59
Ok i think i get it$hash3 = hash('SHA256',$data2);$hash4 = pack("H*", $hash3);$hash5 = bin2hex($hash4);echo $hash5 -- the sameecho $hash3 -- the sameecho $hash4 -- "‚•É+3�6B™Ó¤R- Kai%¡þÊnª
cryptscript
2010-07-29 18:28:21