1
votes

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:

let message = encrypt("hello word!","public_key");
let decrypt_message = decrypt(message, "public_key");

/* the decrypt() method should throws error cuz the user shouldn't be able to
 * decrypt his own message with the public_key
 */

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

thank you in advance ♥

1

1 Answers

1
votes

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.