5

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
Community
  • 1
  • 1
anij
  • 1,322
  • 5
  • 23
  • 39
  • To simplify your problem, you might use https://localhost:8080/app/?data={encrypted_data} to simplify your problem. Are you looking to hide the data or to authenticate whether the data has been changed? – ErstwhileIII Jun 18 '14 at 14:01
  • No man, the requirement is not to use '?' or pass as URL parameter. Secondly, I'm encoding because I'm passing one URL on that {encryped_data}, which again contains some '/'. :D – anij Jun 18 '14 at 14:12
  • 2
    There are URL-safe Base64 variants, and most Base64 libraries provide an overloaded encode/decode methods that work with such variants. Check [iHarder Base64 URL_SAFE](http://iharder.sourceforge.net/current/java/base64/api/Base64.html#URL_SAFE) for example. – Oleg Estekhin Jun 18 '14 at 16:17

1 Answers1

2

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

example:

Encode string to base32 string in Java

Community
  • 1
  • 1
Wajdy Essam
  • 4,280
  • 3
  • 28
  • 33
  • There is also a Base64 variant where `+` and `/` are replaced. See http://en.wikipedia.org/wiki/Base64 . Especially in **Java 8** there is now http://docs.oracle.com/javase/8/docs/api/java/util/Base64.Encoder.html – Joop Eggen Jun 24 '14 at 12:27