Encrypt javascript code to prevent javascript injection in MongoDB? -


i'm going store javascript code in mongodb (no-sql) database.

but prevent javascript injection want encrypt javascript code in string.

is there way encrypt , decrypt without having defect javascript code?

there lot of stuff other web considering this.

i suggest have @ jquery plugin encryption jquery plugin encryption

i personnally have not used 1 of these encryption tools, integration seems pretty easy, , of course should generate random encryption key :

for instance here example of jqcrypt:

    <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.jqcrypt.js"></script> <script type="text/javascript">   $(function(){       $('#form_id').jqcrypt({           keyname:    'jqckval',           randomkey:  false,           key:        'some_key_value',           callback: function(form){                form.submit();            }       });   }); </script> 

and here should decrypting example

function c2sdecrypt($s,$k){     $k = base64_decode(urldecode($k));     $s = urldecode($s);     $k = str_split(str_pad('', strlen($s), $k));     $sa = str_split($s);     foreach($sa $i=>$v){         $t = ord($v)-ord($k[$i]);         $sa[$i] = chr( $t < 0 ?($t+256):$t);     }     return urldecode(join('', $sa));  } 

from jqcrypt plugin.

the strong point generation of strong hash in web page, encrypt value return web page client.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -