I've read through documentation here: https://laravel.com/docs/5.8/encryption But, there is no specification about the size limit of the data to be encrypted.
I want to encrypt an array using laravel encryption. The array can have any number of elements. This encrypted value will be one of the url parameter later. So, I have to figure out the will it work or not when array size is too large.
Any kind of suggestion is appreciated.
The maximum size of the variable you can pass to the Laravel helper method - encrypt()
is the maximum size allowed for a String variable in PHP as it's specification requires a String parameter.
According to the PHP Manual, the maximum size for a String in 32bit systems is 2GB. In 64bit systems, the size of a String is unrestricted - The only possible size restriction would be the size of physical memory available to your application.
Any PHP method (whether in-built or user-defined) that requires a string parameter will benefit from these maximum size specifications.
Laravel uses AES in CBC mode for encryption. Block cipher modes of operation are used to encrypt an arbitrary amount of data with a block cipher which would otherwise be limited to a single block (i.e. 16 bytes for AES).
A block cipher by itself is only suitable for the secure cryptographic transformation (encryption or decryption) of one fixed-length group of bits called a block. A mode of operation describes how to repeatedly apply a cipher's single-block operation to securely transform amounts of data larger than a block.
However, the more data is encrypted under a single key, the more likely it is to get the same block of ciphertext twice. This can then be exploited to recover some plaintext. Therefore it is necessary to stop using a particular encryption key after some time.
For AES in CBC mode the usual suggestion is to rotate keys after encrypting a few hundred MB of data to be super-safe, and after a few ten TB of data at the latest. See this question and this question on Cryptography SE for the reasoning.