I am using javax.crypto.Cipher to encrypt a String I want to send back to the client side:
public byte[] encrypt(String message)
throws Exception {
Cipher cipher = Cipher.getInstance(m_ALGORITHM);
PrivateKey privateKey = m_kp.getPrivate();
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
return cipher.doFinal(message.getBytes());
}
My encrypt and decrypet function works well at the server side but when the encrypted String goes back to the client as :
�zXi�Xq�����.��PiO��dM-�d��a��\`�"����uJ��yu
The client console show:
Uncaught SyntaxError: Invalid or unexpected token
I have tried to UTF-8 format the String:
String utfEnc = new String(encrypetBytes, "UTF-8");
but it does not work and I am out of ideas.
The encryption is Java function my jsp page uses(in my jsp):
Encryptor enc = new Encryptor(request);
byte[] encData = enc.encrypt(data);
The goal is the send this data via http:
$.ajax({
type: "POST",
url: serverUrl,
data: <%=encData%>, //Uncaught SyntaxError: Invalid or unexpected token
success: function(){
console.log('done');
}
});
Thanks for any help.