Convert string to SHA1 and base64

I am having a problem converting a string, say: "TestPassword" to SHA1 and base64.

Generally according to this site: http://www.online-convert.com/result/1f76972748a7d186198171e9a11e9493

I need to provide the below results:

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

      

No problem converting the string to SHA1, but I don't know how to convert it back to base64 as it needs to process every two characters as a hex byte and then pass it to the base64 function.

Maybe someone will try to shed some light on it or insert a piece of code how to do this?

Thank!

+3


source to share


2 answers


Base64 encoding must be in the original binary version of the SHA1 summary, not hex encoding.

You can get this raw version by passing true

for a $raw_output

function parameter sha1()

:



$base64 = base64_encode(sha1("TestPassword", true));

      

+10


source


I think this is a late answer, but I achieved this exact value using raw md5 and then convert it to base64:



$base64 = base64_encode(hash("md5", "myPassword", true));

      

+1


source







All Articles