I was experimenting with encryption and hashing when I came across this weird problem.
So I was trying to generate a 128bit key for an AES function, so I did the following to generate the hash and check the hash in base64 format:
It returned this: MaC/vRE/Qq0cCGy1p3MkqA==
However, the same thing I did in PHP is giving me a different hash result with this code:
And it is giving me problem with encryption and decryption, something encrypted in B4X is not being decrypted in PHP because the keys are different.
Why is this happening, and how to make both the outputs same?
So I was trying to generate a 128bit key for an AES function, so I did the following to generate the hash and check the hash in base64 format:
B4X:
Dim Secret as String
Dim j() as byte
Dim md as MessageDigest
Dim su as StringUtils
Secret = "Hello B4J"
j = md.GetMessageDigest(Secret.GetBytes("UTF8"),"MD5")
Log(su.EncodeBase64(j))
It returned this: MaC/vRE/Qq0cCGy1p3MkqA==
However, the same thing I did in PHP is giving me a different hash result with this code:
PHP:
<?php
$p = "Hello B4J";
$p = md5($p);
echo(base64_encode($p));
?>
And it is giving me problem with encryption and decryption, something encrypted in B4X is not being decrypted in PHP because the keys are different.
Why is this happening, and how to make both the outputs same?