Created
April 13, 2020 13:05
-
-
Save CoreProgramm/5f6bb494c96341e4df315615e1864748 to your computer and use it in GitHub Desktop.
Encrypt in JavaScript and Decrypt in C# With AES Algorithm in ASP.Net MVC
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
@model Encrypt_JavaScript_Decrypt_Csharp.Models.Login | |
@{ | |
ViewBag.Title = "Login"; | |
<script src="../../Scripts/aes.js" type="text/javascript"></script> | |
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function CheckData() { | |
var txtUserName = $('#Username').val(); | |
var txtpassword = $('#Password').val(); | |
if (txtUserName == "") { | |
alert('Please enter UserName'); | |
return false; | |
} | |
else if (txtpassword == "") { | |
alert('Please enter Password'); | |
return false; | |
} | |
else { | |
var key = CryptoJS.enc.Utf8.parse('8080808080808080'); | |
var iv = CryptoJS.enc.Utf8.parse('8080808080808080'); | |
var encryptedlogin = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(txtUserName), key, | |
{ keySize: 128 / 8, iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); | |
$('#Username').val(encryptedlogin); | |
var encryptedpassword = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(txtpassword), key, | |
{ keySize: 128 / 8, iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); | |
$('#Password').val(encryptedpassword); | |
} | |
} | |
</script> | |
} | |
<h2> | |
Login | |
</h2> | |
@using (Html.BeginForm("Index","Home", FormMethod.Post)) | |
{ | |
if (TempData["notice"] != null) | |
{ | |
<p>@TempData["notice"]</p> | |
} | |
@Html.AntiForgeryToken() | |
@Html.ValidationSummary(true) | |
<fieldset> | |
<legend>Userlogin</legend> | |
<div class="editor-label"> | |
@Html.LabelFor(model => model.Username) | |
</div> | |
<div class="editor-field"> | |
@Html.EditorFor(model => model.Username) | |
@Html.HiddenFor(model => model.Username) | |
@Html.ValidationMessageFor(model => model.Username) | |
</div> | |
<div class="editor-label"> | |
@Html.LabelFor(model => model.Password) | |
</div> | |
<div class="editor-field"> | |
@Html.EditorFor(model => model.Password) | |
@Html.HiddenFor(model => model.Password) | |
@Html.ValidationMessageFor(model => model.Password) | |
</div> | |
<p> | |
<input type="submit" onclick="CheckData();" value="LOGIN" /></p> | |
</fieldset> | |
} | |
@section Scripts { | |
@Scripts.Render("~/bundles/jqueryval") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment