Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have found two solutions to this. Here is the first one.</p> <p>Add back in padding to Base64 encoded strings. Inspiration for this came from <a href="http://fi.am/entry/urlsafe-base64-encodingdecoding-in-two-lines/" rel="nofollow noreferrer">http://fi.am/entry/urlsafe-base64-encodingdecoding-in-two-lines/</a></p> <p>In this solution, the JavaScript stays the same (base64 encode everything) and the server side looks like:</p> <pre><code>public class CookieDecoder { private static final Log log = LogFactory.getLog(CookieDecoder.class); /** * @param cookieValue The value of the cookie to decode * @return Returns the decoded string */ public String decode(String cookieValue) { if (cookieValue == null || "".equals(cookieValue)) { return null; } if (!cookieValue.endsWith("=")) { cookieValue = padString(cookieValue); } if (log.isDebugEnabled()) { log.debug("Decoding string: " + cookieValue); } Base64 base64 = new Base64(); byte[] encodedBytes = cookieValue.getBytes(); byte[] decodedBytes = base64.decode(encodedBytes); String result = new String(decodedBytes); if (log.isDebugEnabled()) { log.debug("Decoded string to: " + result); } return result; } private String padString(String value) { int mod = value.length() % 4; if (mod &lt;= 0) { return value; } int numEqs = 4 - mod; if (log.isDebugEnabled()) { log.debug("Padding value with " + numEqs + " = signs"); } for (int i = 0; i &lt; numEqs; i++) { value += "="; } return value; } } </code></pre> <p>On the JavaScript side, you just need to make sure you base64 encode the values:</p> <pre><code>var encodedValue = this.base64.encode(value); document.cookie = name + "=" + encodedValue + "; expires=" + this.expires.toGMTString() + "; path=" + this.path; </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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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