I have this code below for encrypting objects, which does a job. But I have an object containing a list of another object. When I encrypt the object I have the error that data must be greater than 256 bytes. When I remove the list, the encryption is managed without error.
public class A {
private List<B> b = new ArrayList<>();
//getter setter
}
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
encryptedBytes = cipher.doFinal(message.getBytes());
} catch (NoSuchPaddingException | NoSuchAlgorithmException | BadPaddingException
| IllegalBlockSizeException | InvalidKeySpecException | InvalidKeyException e) {
e.printStackTrace();
}