0

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();
}
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
boycod3
  • 5,033
  • 11
  • 58
  • 87