openssl_encrypt
Encrypts data
&reftitle.description;
stringfalseopenssl_encrypt
#[\SensitiveParameter]stringdata
stringcipher_algo
#[\SensitiveParameter]stringpassphrase
intoptions0
stringiv""
stringtag&null;
stringaad""
inttag_length16
Encrypts given data with given method and passphrase, returns a raw
or base64 encoded string
&reftitle.parameters;
data
The plaintext message data to be encrypted.
cipher_algo
The cipher method. For a list of available cipher methods, use openssl_get_cipher_methods.
passphrase
The passphrase. If the passphrase is shorter than expected, it is silently padded with
NUL characters; if the passphrase is longer than expected, it is
silently truncated.
There is no key derivation function used for passphrase as its name
might suggest. The only operation used is padding with NUL characters
or truncation if the length is different than expected.
options
options is a bitwise disjunction of the flags
OPENSSL_RAW_DATA, and
OPENSSL_ZERO_PADDING
or OPENSSL_DONT_ZERO_PAD_KEY.
iv
A non-&null; Initialization Vector. If the IV is shorter than expected, it is padded with
NUL characters and warning is emitted; if the passphrase is longer
than expected, it is truncated and warning is emitted.
tag
The authentication tag passed by reference when using AEAD cipher mode (GCM or CCM).
aad
Additional authenticated data.
tag_length
The length of the authentication tag. Its value can be between 4 and 16 for GCM mode.
&reftitle.returnvalues;
Returns the encrypted string on success&return.falseforfailure;.
&reftitle.errors;
Emits an E_WARNING level error if an unknown cipher
algorithm is passed in via the cipher_algo parameter.
Emits an E_WARNING level error if an empty value is passed
in via the iv parameter.
&reftitle.changelog;
&Version;
&Description;
7.1.0
The tag, aad and tag_length parameters were added.
&reftitle.examples;
AES Authenticated Encryption in GCM mode example for PHP 7.1+
]]>
AES Authenticated Encryption example prior to PHP 7.1
]]>
&reftitle.seealso;
openssl_decrypt