Note that there are some explanatory texts on larger screens.

plurals
  1. POAvoiding line breaks in encrypted and encoded URL string
    primarykey
    data
    text
    <p>I am trying to implement a simple string encoder to obfuscates some parts of a URL string (to prevent them from getting mucked with by a user). I'm using code nearly identical to the sample in the <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#SimpleEncrEx" rel="nofollow noreferrer">JCA guide</a>, except: </p> <ul> <li>using DES (assuming it's a little faster than AES, and requires a smaller key) and</li> <li>Base64 en/decoding the string to make sure it stays safe for a URL.</li> </ul> <p>For reasons I can't understand, the output string ends up with linebreaks, which I presume won't work. I can't figure out what's causing this. Suggestions on something similar that's easier or pointers to some other resources to read? I'm finding all the cryptography references a bit over my head (and overkill), but a simple ROT13 implementation won't work since I want to deal with a larger character set (and don't want to waste time implementing something likely to have issues with obscure characters i didn't think of).</p> <p>Sample input (no line break): </p> <pre><code>http://maps.google.com/maps?q=kansas&amp;hl=en&amp;sll=42.358431,-71.059773&amp;sspn=0.415552,0.718918&amp;hnear=Kansas&amp;t=m&amp;z=7 </code></pre> <p>Sample Output (line breaks as shown below): </p> <pre><code>GstikIiULcJSGEU2NWNTpyucSWUFENptYk4m5lD8RJl8l1CuspiuXiE9a07fUEAGM/tC7h0Vzus+ jAH6cT4Wtz2RUlBdGf8WtQxVDKZVOzKwi84eQh2kZT9T3KomlnPOu2owJ/2RAEvG+QuGem5UGw== </code></pre> <p>my encode snippet:</p> <pre><code>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); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload