Last active
March 25, 2019 16:18
-
-
Save louismullie/6159542 to your computer and use it in GitHub Desktop.
Encrypted AJAX wrapper for jQuery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var key = 'password'; | |
$.encAjax = function (url, options) { | |
options.data = options.data || {}; | |
var data = JSON.stringify(options.data); | |
var encryptedData = sjcl.encrypt(key, data); | |
options.data = { data: encryptedData }; | |
var success = options.success; | |
options.success = function (jsonResponse) { | |
var txtResponse = JSON.stringify(jsonResponse); | |
var decryptedResponse = sjcl.decrypt(key, txtResponse); | |
success(JSON.parse(decryptedResponse)); | |
}; | |
$.ajax(url, options); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment