Skip to content

Instantly share code, notes, and snippets.

@peiyush13
Created September 5, 2019 20:01
Show Gist options
  • Save peiyush13/02db0d1e39f3b5e85cf12e1ca5bae7d0 to your computer and use it in GitHub Desktop.
Save peiyush13/02db0d1e39f3b5e85cf12e1ca5bae7d0 to your computer and use it in GitHub Desktop.
client side encryption upon form submission
$(document).ready(function(){
$('form').submit(function( event ) {
var encrypt = new JSEncrypt();
$('[data-encrypt]').each(function(){
var unencrypted = $(this);
encrypt.setKey($('#public_key').attr('data-value'));
var encrypted = encrypt.encrypt(unencrypted.val());
if(encrypted) {
unencrypted.val(encrypted);
}
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment