Avoiding line breaks in encrypted and encoded URL string

I am trying to implement a simple string encoder to trick some parts of a URL string (so that they cannot be disabled by the user). I use code that is almost identical to the sample in the JCA guide , except:

  • using DES (assuming it is slightly faster than AES and requires a smaller key) and
  • Base64 en / decode the string to make sure it stays safe for the url.

For reasons that I cannot understand, the output line ends with line breaks, which I believe will not work. I cannot understand what causes this. Suggestions for something similar that is easier to read for others? I find all the cryptographic links a little over my head (and overkill), but a simple implementation of ROT13 will not work, since I want to deal with a large set of characters (and do not want to waste time implementing something that might have problems with obscure characters that I didn’t think about).

Input example (without line break):

http://maps.google.com/maps?q=kansas&hl=en&sll=42.358431,-71.059773&sspn=0.415552,0.718918&hnear=Kansas&t=m&z=7

Output example (line breaks as shown below):

GstikIiULcJSGEU2NWNTpyucSWUFENptYk4m5lD8RJl8l1CuspiuXiE9a07fUEAGM/tC7h0Vzus+
jAH6cT4Wtz2RUlBdGf8WtQxVDKZVOzKwi84eQh2kZT9T3KomlnPOu2owJ/2RAEvG+QuGem5UGw==

my code snippet:

final Key key = new SecretKeySpec(seed.getBytes(), "DES");
final Cipher c = Cipher.getInstance("DES");
c.init(Cipher.ENCRYPT_MODE, key);
final byte[] encVal = c.doFinal(s.getBytes());
return new BASE64Encoder().encode(encVal);
+5
source share
4 answers

Base64 (chunk) . , . , Apache Commons linelength, ( ), .

: , DES . , "" ? ? .

+7

base64Str = base64Str.replaceAll("(?:\\r\\n|\\n\\r|\\n|\\r)", "") .

, . . , , , . " ", com.sun.org.apache.xml.internal.security.utils.Base64 .

+11

, DES AES ( , ), , , AES .

-, , (DES AES) / . base-64, , .

, base-64 . base-64 , , . , , , 80 (, , ). , , , , .

+1

VA...

:

return new BASE64Encoder().encode(encVal);

:

return new android.util.Base64.encodeToString(encVal, Base64.NO_WRAP);

import android.util.Base64;

...

return new BASE64.encodeToString(encVal, Base64.NO_WRAP);
+1

All Articles