Reputation: 1913
I am having problem with converting the string, lets say: "TestPassword" to SHA1 and to base64.
Generally according to that site: http://www.online-convert.com/result/1f76972748a7d186198171e9a11e9493
I should be given the results below for the above password:
hex: 6250625b226df62870ae23af8d3fac0760d71588
HEX: 6250625B226DF62870AE23AF8D3FAC0760D71588
h:e:x: 62:50:62:5b:22:6d:f6:28:70:ae:23:af:8d:3f:ac:07:60:d7:15:88
base64: YlBiWyJt9ihwriOvjT+sB2DXFYg= <-- That is what I would like to achieve ...
There is no problem with converting string to SHA1 but i don't know how to convert it again to base64 as there is a need to treat every two characters as a hex byte and then pass it to base64 function.
Could someone please throw light on it or paste code snippet how to do it?
Thank You!
Upvotes: 5
Views: 15279
Reputation: 1293
Hi please run this command in terminal,
echo 6250625B226DF62870AE23AF8D3FAC0760D71588 | xxd -r -p | openssl base64
Upvotes: 0
Reputation: 11
I think is a late response but I achieved that exact value by using the raw md5 and then converting it to base64:
$base64 = base64_encode(hash("md5", "myPassword", true));
Upvotes: 1
Reputation: 339816
The Base64 encoding should be performed on the raw binary version of the SHA1 digest, not the hex encoding of it.
You can get that raw version by passing true
for the $raw_output
parameter of the sha1()
function:
$base64 = base64_encode(sha1("TestPassword", true));
Upvotes: 16