To AES encrypt in PHP, you can use the openssl_encrypt()
function. Here is an example code block for AES-256 encryption:
main.php511 chars16 lines
In the code above, we set the encryption key and initialization vector (IV) to be used with AES-256-CBC encryption. We then set the plaintext message to be encrypted and use the openssl_encrypt()
function to generate the encrypted message. Finally, we convert the encrypted message to base64 encoding and output it.
Note that you should always use a strong and secure encryption key, as well as a random and unpredictable IV, to ensure the security of your encrypted messages.
gistlibby LogSnag