4

I'm using localStorage in an application.

I'm using an XOR bitshift operation to mask the data before it goes into storage.

Here is the masking function:

    encrypt: function (str) {
        var encoded = [];

        if (!App.crypto.key) {
            App.crypto.init();
        }

        for (var i = 0, len = str.length; i < len; i++) {
            var a = str.charCodeAt(i);
            var b = a ^ App.crypto.key.charCodeAt(App.crypto.key % i);
            encoded.push(String.fromCharCode(b));
        }

        return encoded.join("");
    }

The value of the key I'm using in this case is "MWZ2cyt2N3JwejhxUjA2V3ptRmwxcmVvU09IbFhORHdOcDRiWGh5SGRZMFU4Ym9VY1Y1WXU5c2d6OXhBdU9wTSt1MlpqcmhXOVBRPQ0K"

When I mask "[]" in IE9 I get some weirdo characters. When I try and set that to localStorage it gives me an invalid argument error. Does anybody know what's going on?

1 Answer 1

7

IE (and Edge, given this hasn't been rewritten yet) stores localStorage as XML, and disallows any character that doesn't match the Char production in XML 1.0; i.e., you can store "any Unicode character, excluding the surrogate blocks, FFFE, and FFFF".

Per specification, this is a bug: there should be no restriction on what can be stored in localStorage (any ECMAScript string should be possible), though this bug has existed since IE8. (In IE8 previews it was possible to corrupt the localStorage backing-store by storing one of the disallowed characters, as when it attempted to parse the XML file it got a parse error!)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.