the issue is that I need to encrypt with a public key on the front end.
I can pass to back end already encrypt (please let me know if this is the rigth way to do it).
I used the follow code on the front end:
<script>
var element=document.getElementById("send")
var password=document.getElementById("password")
element.addEventListener("click", function(){
encryptFront(password.value)
});
var publicKeyFile="publicKeyString"
function encryptFront(jsonPassword) {
console.log("test")
const JSEncrypt = import ("jsencrypt"); // Introduce module
const str = "i will be encrypto";
console.log(str)
const encrypt = new JSEncrypt(); // instantiate encrypted objects
Encrypt.setPublicKey (publicKeyFile); //Set public key
const encryptoPasswd = encrypt.encrypt(str) // encrypted plaintext
console.log(encryptoPasswd)
}
</script>
but It's not working show me the follow errors:
"Uncaught SyntaxError: Cannot use import statement outside a module"
note:
on the back end I'm using the follow lib var to get the true password
RSA = require('node-crypto-js').RSA;
var Crypt = require('node-crypto-js').Crypt;
crypt.decrypt(privateKey, encrypted);
question from:
https://stackoverflow.com/questions/66049173/encrypt-password-on-the-front-end 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…