I'm trying to used CryptoJS
to encrypt the login username and password, I always getting the error Can't find variable: CryptoJS
, Here's the steps that I follow:
Include the
ads.js
file injs
folder in wwwroot directory.Include
AESEncryption.cs
to the project.added
<script src="~/js/aes.js" type="text/javascript"></script>
to the end of_Layout.cshtml
page.Using the following function in
Index.cshtml
<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); } }
I always getting Can't find variable: CryptoJS