jqCrypt POST Method Encryption
A simple jQuery plugin to encrypt form data client-side and pass it (with an obfuscated key) to the processor via the POST method.
Demo:
Implementation:
<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>
Implementation of the jqCrypt plugin consists simply of including the jQuery core, the plugin file, and associating the function with the id of the form to be encrypted.
Parameters:
keyname: The name of the key, this is the name of the form field containing the key value (Default: 'jqckval')
randomkey: Tells the system wether or not to use a random key or one of your choosing (Default: true)
key: If 'randomkey' parameter is set to 'false' this is the key that will be used instead (Default: '123456')
callback: function to be fired after fields have been encrypted (Default: submit form)
Decrypting (PHP):
The following PHP function can be used to decrypt the values using PHP:
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 as $i=>$v){
$t = ord($v)-ord($k[$i]);
$sa[$i] = chr( $t < 0 ?($t+256):$t);
}
return urldecode(join('', $sa));
}
Download:
Download the jquery.jqcrypt.js plugin (with example)
Responses to this Article:
Loading Comments...
I am a web developer, designer, and consultant located in the La Crosse / Onalaska Wisconsin region with
over twelve years experience developing and managing projects ranging from large applications and cloud-based
business solutions to social/new media campaigns, to complete system and infrastructure implementation.