admin管理员组

文章数量:1417691

I'm trying to build a Diary system, with local En/Decryption so that the entries can only be read by the user with the password, which is not stored on the server. The Crypto should be done with Javascript(CryptoJS), but I have to manipulate the data of a HTML-form, before it's send. If it's possible, this should be done without JQuery, because of performance and bandwidth. Bacause I'm relatively new to java script, I don't know, how to manipulate the data of the form, when the submit button was clicked ? :)

var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");

I'm trying to build a Diary system, with local En/Decryption so that the entries can only be read by the user with the password, which is not stored on the server. The Crypto should be done with Javascript(CryptoJS), but I have to manipulate the data of a HTML-form, before it's send. If it's possible, this should be done without JQuery, because of performance and bandwidth. Bacause I'm relatively new to java script, I don't know, how to manipulate the data of the form, when the submit button was clicked ? :)

var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
Share Improve this question edited Oct 25, 2019 at 19:07 infinitecode 271 silver badge8 bronze badges asked Apr 11, 2015 at 23:02 Bonar ScriptaBonar Scripta 751 gold badge2 silver badges7 bronze badges 4
  • as long as your server can handle gobblygook instead of normal post data, then you can just send the blob over and echo it out later un-impeded. – dandavis Commented Apr 11, 2015 at 23:11
  • yes, but i'm new to javasctipt, and wanted to know, how to manipulate the form when the submit butten is clicked :) – Bonar Scripta Commented Apr 11, 2015 at 23:13
  • 1 Make your own research on how to capture form data and send it, it's not a unique problem. – zerkms Commented Apr 11, 2015 at 23:18
  • well, you can't use the submit button anymore. at least, not with out totally re-implementing it anyway... – dandavis Commented Apr 11, 2015 at 23:21
Add a ment  | 

1 Answer 1

Reset to default 2

I dont know why u think jquery is slow or gives u a large amount of data to send. But u can transform any jquery code into normal javascript so this should be no problem. I will give some hints in jquery because i dont know all the things in pure js and will not google this for u :)

$("#submitbutton").click(function(event){
    event.preventDefault(); //Prevent form beeing send
    var allFormDatas = {}; //Object thats stores all form data
    $.each($("#youtform").find("input"),function() { //loop over all inputs in the form
        allFormDatas[$(this).attr("name")] = $(this).val(); //Gets the value from an form element and puts into "allFormDatas"
    });

    var stringForEncryption = JSON.stringify(allFormDatas); //Now we have one long Json string for encryption
    var encrypted = CryptoJS.AES.encrypt(stringForEncryption, "Secret Passphrase");
    //Now use $.post here to send post data to your backend.
});

//Encryption should be 
encrypted>decrypt>parseJson>jsObject

PS: this is not tested and will not get dropdown and checkbox elements but you get an idea i hope :)


EDIT: A smarter solution... thanks to @dandavis:

$( "form" ).on( "submit", function( event ) {
  event.preventDefault();
  var formString = $( this ).serialize(); // All data in one String.
  var encrypted = CryptoJS.AES.encrypt(formString, "Secret Passphrase");
  //Now use $.post here to send post data to your backend.
});

本文标签: encryptionJavascript Encrypt Form before sending with AESStack Overflow