Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS frontend encryption with public-private key

I'm trying to encrypt some strings in the frontend with javascript with the some public-private key method in which only the backend could decrypt with the private key, is this possible? how can I achieve it?

I don't mind if it has a really basic encryption as long it has a public and private key

// This is an EXAMPLE of what I want:

//Frontend code:
let message = encrypt("hello word!","public_key");

//Nodejs backend code:
let decrypt_message = decrypt(message, "private_key");

also notice that I'm already using HTTPS but having extra security doesn't hurt anyone :)

thank you in advance ♥

like image 528
mentamarindo Avatar asked Sep 16 '25 09:09

mentamarindo


1 Answers

CryptoJS / crypto-js and JSEncrypt / jsencrypt are the libraries you can use to do so.

You need to encrypt your data encryption key to send to backend and then you can decode this on backend using Private key and encryption key.

like image 54
Anks Avatar answered Sep 19 '25 00:09

Anks