https://kotlinlang.org logo
Title
o

oday

11/25/2019, 11:55 AM
hey so I’m having an issue with Base64 encoding, it seems whenever I encode a certain string in my app, the result is different from when I use something like base64encode.org, always different
s

spand

11/25/2019, 11:56 AM
Charset difference maybe ?
o

oday

11/25/2019, 11:56 AM
i just tried on a much smaller string.. it was the same
hm!
b

bjartek

11/25/2019, 12:04 PM
check that both strings have or do not have a newline at the end?
u

Ubi

11/25/2019, 12:09 PM
@bjartek is most probably correct. Try to
.trim()
the string before encoding to test. (Note! trim only if you really want to remove empty spaces or
\n
at the end of your string)
o

oday

11/25/2019, 12:14 PM
the string was littered with \n
it was like this
"{\n" +
                    "\"userId\":\"${fireAuth.currentUser?.uid}\",\n" +
                    "\"carId\":\"${carDetails.id}\",\n" +
                    "\"car\":\"${carDetails.make} ${carDetails.model} ${carDetails.submodel} ${carDetails.year}\",\n" +
                    "\"sellerPhone\":\"+971504421995\",\n" +
                    "\"buyerEmail":"${fireAuth.currentUser?.email}\"" +
                    "\n}"
now its like this
"{" +
                    "\"userId\":\"${fireAuth.currentUser?.uid}\"," +
                    "\"carId\":\"${carDetails.id}\"," +
                    "\"car\":\"${carDetails.make} ${carDetails.model} ${carDetails.submodel} ${carDetails.year}\"," +
                    "\"sellerPhone\":\"+971504421995\"," +
                    "\"buyerEmail":"${fireAuth.currentUser?.email}\"" +
                    "}"
produces the correct encoding result
👍 1