I have a JsonObject (Gson) I want to encrypt this json with Aes256 before I send it to the server, so I have to convert it to Base64 first
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("command", "abc");
String body = Base64.encodeToString(jsonObject.toString().getBytes("UTF-8"), Base64.NO_WRAP);
String finalBody = aesKeyIv.encrypt(body);
However it sends malformed json because it cannot convert properly.
EDIT: This is for Android
My encrypt method:
public String encrypt(String value) throws Exception {
byte[] encrypted = cipherEnc.doFinal(value.getBytes());
return Base64.encodeToString(encrypted, Base64.NO_WRAP);
}
encrypt()method is defect.