Hi all,
I am facing a big problem with my code, I am using a js file with AES encryption algorithm. The problem is while I am publishing my application the encryption JS file is showing while I inspect my code in the browser is there any method to hide the JS file in the layout page using asp.net core MVC
when I clicked on the above link the encryption key and other details are visible. Please help me to solve this issue. Is it possible to hide js file?
JavaScript
var key = CryptoJS.enc.Utf8.parse('abcde');
var iv = CryptoJS.enc.Utf8.parse('efghukkkhs');
let code = (function () {
return {
//
return encryptedMessage.toString();
},
decryptMessage: function (encryptedMessage = '') {
}).toString(CryptoJS.enc.Utf8);
return _enid;
}
}
})();
Rijwan AnsariRank #82 · 24.2K reputationPosted Dec 4, 2021, 1:10 PM EST
There is no way to hide the JS code. JS-Scripts are running inside your Browser. So the Browser must know the JS-Scripts. And if the Browser know it, the user can have a look at them.
But all you can do is disable the the right click of mouse button using below code:
function disableclick(event){ if(event.button==2){ // this value is 3 for some othe browser // Rest of code return false; } }Also not that you need to disable F12 key since pressing F12 open the developers console, which is actually bypass right click event
Rijwan AnsariRank #82 · 24.2K reputationPosted Dec 4, 2021, 1:12 PM EST
Also disabled few keys as shown
document.addEventListener('keydown', function() { if (event.keyCode == 123) { alert("This function has been disabled to prevent you from stealing my code!"); return false; } else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { alert("This function has been disabled to prevent you from stealing my code!"); return false; } else if (event.ctrlKey && event.keyCode == 85) { alert("This function has been disabled to prevent you from stealing my code!"); return false; } }, false); if (document.addEventListener) { document.addEventListener('contextmenu', function(e) { alert("This function has been disabled to prevent you from stealing my code!"); e.preventDefault(); }, false); } else { document.attachEvent('oncontextmenu', function() { alert("This function has been disabled to prevent you from stealing my code!"); window.event.returnValue = false; }); }Satya KarkiRank #78 · 24.6K reputationPosted Dec 4, 2021, 1:13 PM EST
Sachin SinghRank #66 · 26.2K reputationPosted Dec 5, 2021, 12:03 AM EST
Better is to store the key in configuration file and read from there
"Crypto": {
"key": "abcd" ,
"Iv":"agaha"
}
In _Layout.cshtml
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration