Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Is there any encoder which will not include forward slash during data encryption?

I need to pass data in encrypted format with URL like this, http://localhost:8080/app/{encrypted_data}

So, is there any encoder which will not include forward slash(/) in encoding?

Please Note: I don't want to replace '/' by another character, manually, from the encoded data.

..............................................................................................................

Edited: comment from Oleg Estekhin of using Base64 URL safe Encoding is also working fine, I'm just adding an example over here.

EXAMPLE: Encode:

String str = "subjects?_d=1";
byte[] bytesEncoded = Base64.encodeBase64URLSafe((str.getBytes()));

Decode:

Base64 decoder = new Base64(true);
byte[] decodedBytes = decoder.decode(new String(bytesEncoded));
System.out.println(new String(decodedBytes));

Output:

c3ViamVjdHM_X2Q9MQ
subjects?_d=1
like image 290
anij Avatar asked Oct 31 '22 21:10

anij


1 Answers

http://en.wikipedia.org/wiki/Base32

example:

Encode string to base32 string in Java

like image 81
Wajdy Essam Avatar answered Nov 08 '22 06:11

Wajdy Essam