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:
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);
source
share