问题
I want to encrypt and decrypt the json object to be passed as URL parameters. is there a jquery mobile plugin which provides the encryption and decryption for this purpose as I found this link :
http://www.jquery4u.com/security/10-jquery-security/
but this has all the outdated plugins.
If there is no option for me in jquery plugins, then I was planning to use this library.
http://crypto.stanford.edu/sjcl/
is this my best option as I want fast and lightweight library because of the URL parameters requirement or do I have a better option?
回答1:
BASE64
If you want some basic encryption that can be also decrypted then you should use plugin for BASE64
encryption/decryption.
This plugin can be found as a part of jQuerySDK and if you want to find out more take a look at this link.
Usage:
$.toBASE64({
foo: 'bar'
});
$.toBASE64(['foo', 'bar']);
$.toBASE64(12345);
$.toBASE64('Lorem ipsum');
MD5, SHA1, XTEA
MD5
and SHA1
are of course much much more secure then BASE64
. Unfortunately they are used only for encoding. Instead of them you can use XTEA
. It works on a same principle like BASE64
but unlike BASE64
you can use a key to encrypt/decrypt your string.
If you want to find out more go to this link.
Usage:
//md5:
$().crypt({method:"md5",source:$("#phrase").val()});
//sha1:
$().crypt({method:"sha1",source:$("#phrase").val()});
//xtea
$().crypt({method:"xteab64enc",source:$("#phrase").val(),keyPass:$("#passPhrase").val()});
$().crypt({method:"xteab64dec",source:xteab64,keyPass:$("#passPhrase").val()});
EDIT :
Regarding your first comment if you read my answer you would find tha BASE64 and XTEA are used to encrypt/decrypt your string. If you want to look past jQuery then there are only 2 relevant possibilities: Crypto-js and Stanford Crypto Library. They are best javascript can provide and difference is just like difference between Coke and Pepsi. At the end what will you use will depend on what are really going to encrypt/decrypt. For everything that is not passwords go with easy solutions like BASE64 or XTEA. For passwords go with Crypto-js orStanford Crypto Library.
来源:https://stackoverflow.com/questions/16581621/jquery-mobile-plugin-for-encryption-decryption