javascript - Trying to send encrypted text via URI - /uDDBA causing "URIError: URI Malformed" -


simple code:

encodeuricomponent("\uddba") 

result:

urierror: uri malformed 

i trying simple encryption take user input text, , password, , encrypt text , save server.

basically trying encode letter "t" - , algorithm has determined should 56762 or ddba in hex.

but looks hex values result in errors if try encode character using encodeuricomponent.

how can solve this?

i need know available range of characters can pass through encodeuricomponent in javascript.

currently doing this:

var xor = 0xddce;  var plaintext = "t".charcodeat(0); var encoded = plaintext ^ xor; var encodedchar = string.fromcharcode(encoded); var uri = "/someuri?character=" + encodeuricomponent(encodedchar);  // how plain text var decoded = encodedchar.charcodeat(0) ^ xor; var decodedchar = string.fromcharcode(decoded); 

this simplified version, xor value static. in real case xor value calculated based on bunch of variables.

assume "/someuri" not built me, , wasn't built receive encrypted data, merely trying use uri.

also, encryption algorithm can changed. xor value generated using simple algorithm using user entered password, , position of character.

i thinking of 1 way make work reduce total number of possible output characters , perform mapping of kind... can't picture code that.

edit:

comments on security of choice of encryption appreciated; however, actual data security aspect not important. want prevent "average" people being able read output encrypted text (assume there can lots of it)

if want average people not see text, use post request or base64.

as actual security useless. attacker doesn't need know plaintext is, needs know user sent site , send same data themself. way prevent use ssl everywhere on site. if wanted, use algorithm found on page's source code decrypt it.


it kinda terrible javascript strings don't validate state right away done free. javascript strings associated utf-16* encoding not sequences valid. not valid have unit value between 0xd800 - 0xdbff when not immediatelly followed 0xdc00 - 0xdfff. , not valid have 0xdc00 - 0xdfff if previous unit value not 0xd800 - 0xdbff.

many things can lead strings violate , because strings don't validate see error later.

you go 8 bits @ time , it'll work.

var xor = 0xddce;  var input = "t",     output = "",     = 0,     ch;  while( isfinite( ch = input.charcodeat(i++) ) {     var xored = ch ^ xor;     output += string.fromcharcode(         (xored & 0xff00) >> 8,         xored & 0xff     ); }  //output "ݺ", or 0x00dd 0x00ba, each char 0x00xx 

*the specification allows using ucs-2 have never seen this. if want sure:

function arestringsutf16() {     try {         var str = decodeuricomponent("%f0%a0%80%80");         return str.charcodeat(0) === 0xd840 &&                str.charcodeat(1) === 0xdc00;     }     catch(e) {         return false;     } } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -