Safe encrypted communication between javascript and back-end using public and private keys