encryption returning false
Author: Superior126Created Jun 11, 2023Updated Sep 13, 2024
I'm trying to encrypt some text with a server public key, but it keeps returning false for whatever reason.
Example pub key from server:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3fQZaIIUSnWYVR++XoHZ
g7GQS996veS+vxY+FF7Oy9Kd943XHrzrYMuCOaOruB6SEZzu2U1xrXnEbTTdwNcj
/WZZCZ1JUPEILhLOPpTB9IE6AsyDfZJZcLeP459Db+5Pw79nf/Q8zyF5d8KS5fWD
INnS38X1EGV/nd7upCcYc8XXeX0a4c2Esd63OK6p2yrlVbjaxPokB6HFf6iZ+WXa
q6a8oO8Fd8wHWSZYnnlGJF0u3kbyas3gHFjiITpTFjQK2QavxzCuR/Slq4SEVMQS
lnF+wWnrhBE/0EcGyepXpQ+EwoNGe3vG04LS2pUPOZswetQrgTYAUFrvgicnvhiw
MQIDAQAB
-----END PUBLIC KEY-----Client code:
// Create a new JSEncrypt instance
const encryptor = new JSEncrypt();
// Set the server's public key
encryptor.setPublicKey(server_pub_key);
// Encrypt the JSON string using the encryptor
const encryptedCredentials = encryptor.encrypt(jsonCredentials);
console.log(encryptedCredentials)Source: travist/jsencrypt