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
1 Answer
Reset to default 2I 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
版权声明:本文标题:encryption - Javascript Encrypt Form before sending with AES - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745274537a2651100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论