PHP Function Sodium_Crypto_Seal
PHP provides a few different methods for encryption, including the PECL extensions mcrypt_encrypt and openssl_encrypt. But if you want to take advantage of newer cryptographic algorithms, you should use the libsodium library instead. This is a more modern and heavily opinionated fork of NaCl that takes much of the decision making away from end users and into the hands of the library maintainers.
Sodium’s crypto_secretbox function implements symmetric authenticated encryption. It accepts a secret key and a nonce that helps generate the ciphertext. When the message is decrypted, it checks a MAC to validate that the message was not tampered with in transit. If the MAC fails to verify, the decryption is aborted.
For asymmetric encryption, Sodium offers a function that uses elliptic curves to encrypt messages between two parties. This is a more complex and slower method than the RSA method used by other PECL extensions, but it provides a similar public/private key relationship.
Libsodium also includes a function for password hashing. It uses Argon2i, which is a winner of the Password Hashing Competition and resistant to side-channel attacks. It is recommended to store passwords in a password manager rather than encrypting them.
Lastly, Libsodium contains an authenticated encryption function that lets you send messages that only the recipient can decrypt. This is a good way to ensure that a message has been transmitted correctly without leaving any traces behind. This function is called crypto_box_seal and it requires a secret key that is kept securely. Then, it requires a nonce that will help to generate the ciphertext and a signature to authenticate the message.