Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to encode back this string?

i have stirng which has been encoded, when i try to decode it with

echo gzdecode(base64_decode('H4sIAAAAAAAACp1SW2/aMBT+L35dkzlOAk7eKujaMBIKhEEzTZVJDmByXeJcCOK/z2Gapr1VkyxZPue7HH/2FfEIMsHFBdlXVFdQOhGyETX24ZhaY4VqUagYQHTFiixNoVSzAAOLImKgB8RqcfLzGDJJgcvstH8O+YLPnE2/6Vw+s1RZ7IOd17OtVe9IEjvnnAfbVer232KPvAmPuDhYY7zYvhlzP8bBNBSL7VPrPnvJwncNr39qHd7yYHdqJbfzzkvTO8e66zv9fDIjwW5215a99rBUU/29LOLyy/uGzhcULG/q9X3Mupd1tem7CZ5ScOLktXnjFuRmZ26fosvxhc5js4l1c7kgSrqd1MdzdynWq0lofn085T9bedEIGh7CPRprZGg6NtkoGmE2JochhqK4t8I8VU95UUCppnmdCcazhkOrFgm7SFgDZcVzmdUVNSypQTJMdawS2drXPIm8Ot1DiWxNG1Eyvt0eUFHCAUrIQqgGVpKHLBloPHp3ppIW1uXQlW+HNuuhIHgKQZ4NmMeKs88zFrNSMCS1KtZA5AhIpdT369+jhE5YWXI5nBSoBBOSfUWCHe+bFJS1tJAwgglRsKFgy8dYTmljXdVG5ic8tjEeLNZ/NNe/VZCbV2IFofxgSF7nX9MVHGUYH/bUfKLbBrUxUXWN/qfnFA6sTsScZ/EHjDUFU4Vg/+4ll4ox/qjxj9svb1MDk1oDAAA='));

everything went well, the problem is when I encode, the result doesn’t work

echo gzencode(base64_encode('{"identity":{"userId":"84bc7897-81dc-4e23-9d91-8819e0eadd24","authToken":"eyJhbGciOiJIUzUxMiJ9.eyJzZXNzaW9uX2lkIjoiZWRmMzVkN2YtN2M0ZS00OWY4LTk0ZDctOWEwMGNlOTM4NzEwIiwiZXhwIjoxNjQ5Njk3MTIzLCJ2ZXJzaW9uIjowfQ.m3_rpkrF_U8LO8e9NDNzzkaxHSsUzxC0D8eIklPvYi9eo5x5WEdygH8Lk5vk35QO2-mWCugjxypSRCc5KAhoqw","deviceId":"9641305a6d60a72f","appId":"com.hopper.mountainview.play","version":{"value":"5.7.2","buildNumber":116827}},"preferences":{"locale":"id_ID","currency":"USD","timeZone":"Asia/Jakarta"},"savedItems":[{"savedItem":"Carriers","state":{"tag":{"timestamp":"2022-04-09T00:11:03.165+07:00"},"SavedItemState":"MostRecent"}},{"savedItem":"Regions","state":{"tag":{"timestamp":"2022-04-01T23:48:02.318+07:00"},"SavedItemState":"MostRecent"}},{"savedItem":"DefaultLinks","state":{"tag":{"timestamp":"2021-08-20T07:00:00.000+07:00"},"SavedItemState":"MostRecent"}}]}'));

and i got the result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

S˒8%^y4%ڠi36n_1s=T%̬,Q-|Ԫ$WKYzi&0
~XpL@cqFX q-2q

how to work well, as above

>Solution :

Think about what is being done for decode and encode. If you break up each operation into 2 steps you will see what you are doing wrong.

base64_decode() takes a string and returns binary data
gzdecode() decodes the binary data into a string

When you want to do the reverse, you must reverse the steps and gzencode first.

gzencode() the json string into binary data
base64_encode() the binary data into a string

So to encode, you would do this:

base64_encode(gzencode('{"identity":...}'));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading