Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encode string to Base64 in android without special character?

I am trying to encode the string data in Base64. I am using this code :

Byte[] url_base64=repl.getBytes("UTF-8");
String con_base64=Base64.encodeToString(url_base64, Base64.NO_WRAP);

Via this code i am getting special characters like ("/","\","\n") etc. How to ignore these special characters in base64 encoding in android.

Please help me if you have any idea about it.

like image 351
Prateek Sharma Avatar asked May 01 '26 20:05

Prateek Sharma


1 Answers

Not sure if this is what you want, but

Base64.encodeToString(url_base64, Base64.NO_WRAP | Base64.URL_SAFE);

will replace "\" with "_"

like image 126
Alexander Sukharev Avatar answered May 03 '26 11:05

Alexander Sukharev