What is the recommended encryption algorithm to use with openssl_encrypt for short strings in PHP?
When encrypting short strings in PHP using openssl_encrypt, it is recommended to use the AES encryption algorithm with a 256-bit key in CBC mode. This algorithm provides a good balance between security and performance for encrypting short strings.
$data = "Hello, world!";
$key = openssl_random_pseudo_bytes(32); // 256-bit key
$iv = openssl_random_pseudo_bytes(16); // 128-bit IV
$ciphertext = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
echo "Encrypted data: " . $ciphertext;
Related Questions
- How can the issue of unwanted tabulation causing layout problems in PHP sprintf() be resolved?
- What are common pitfalls when using PHP to generate dynamic tables, like highscore tables, and how can they be avoided?
- Are there any potential drawbacks or limitations to using array_walk/map for modifying array values in PHP?