Very important to recognize the maximum size $data string constraint and its relation to SSL bit size as pointed out by others. Before I addressed the maximum size limit through blocking the data, I was receiving these types of errors from openssl_error_string():
- error:0906D06C:PEM routines:PEM_read_bio:no start line OR
- error:0E06D06C:configuration file routines:NCONF_get_string:no value
Using a key (sha512, OPENSSL_KEYTYPE_RSA) with 2048 bits, I had a maximum message size of 245 bytes and 4096 bits yielded a max size of 502 bytes. So if you change your key size later, in particular if you reduce the size of it, be aware it affects your maximum encryption length.