# Cryptography and Security

> Section in “New and Extended Functionality” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/cryptography-and-security/>

## In this section

- [New Hashing Algorithm for Passwords](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/new-hashing-algorithm-for-passwords/index.html.md): password_hash() supports Argon2i since PHP 7.2 and the recommended Argon2id since PHP 7.3, tunable via the memory_cost, time_cost, and threads options.
- [crc32c Hashing Algorithm](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/crc32c-hashing-algorithm/index.html.md): PHP 7.4 adds CRC-32C, the cyclic redundancy check used by btrfs, ext4, and iSCSI, to the hash extension as the crc32c algorithm for hash().
- [mail() and mb_send_mail() Hardened Against Header Injections](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/mail-and-mb_send_mail-hardened-against-header-injections/index.html.md): PHP 7.2 parses and filters the additional_headers parameter of mail() and mb_send_mail() to prevent header injections, and also accepts it as an array.
- [Secure unserialize()](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/secure-unserialize/index.html.md): PHP 7 adds an options parameter to unserialize() whose allowed_classes entry restricts which classes may be unserialized, limiting unwanted code execution.
- [max_depth Option for unserialize()](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/max_depth-option-for-unserialize/index.html.md): PHP 7.4 introduces the max_depth option for unserialize() and the unserialize_max_depth ini setting to guard against deeply nested structures.
- [Better random source for uniqid()](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/better-random-source-for-uniqid/index.html.md): PHP 7 changes the internal source of randomness used by uniqid(), making collisions less likely; the identifiers remain unsuitable for cryptography.
- [Improved SSL/TLS](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/improved-ssltls/index.html.md): Starting with PHP 7.2, tls:// stream connections advertise support for TLS up to 1.2 by default, and the ssl:// scheme becomes an alias for tls://.
- [Enhanced Cryptography Features](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/enhanced-cryptography-features/index.html.md): hash_hmac() and hash_pbkdf2() now reject non-cryptographic hashes, PHP 7.1.2 adds hash_hkdf() for key derivation, and PHP 7.2 bundles libsodium.
- [OpenSSL](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/openssl/index.html.md): OpenSSL changes in PHP 7: ALPN support, crypto meta data through stream_get_meta_data(), removed TLS context options, and no more SSLv2 as of PHP 7.1.
- [Cryptographically Secure Pseudo-Random Number Generator (CSPRNG)](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/cryptographically-secure-pseudo-random-number-generator-csprng/index.html.md): PHP 7 adds random_bytes() and random_int() as an easy to use and portable cryptographically secure pseudo-random number generator (CSPRNG).
- [Filtering Syslog Messages](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/filtering-syslog-messages/index.html.md): PHP 7.3 introduces the syslog.filter configuration option with the values no-ctrl, ascii, all, and raw for filtering messages sent with syslog().
- [Same-Site Cookies](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/same-site-cookies/index.html.md): With PHP 7.3, session_set_cookie_params(), setcookie(), and setrawcookie() accept an options array that includes the samesite attribute against CSRF.

---

Previous: [New Configuration Settings in PHP-FPM](https://php7explained.com/new-and-extended-functionality/io-and-filesystem/new-configuration-settings-in-php-fpm/index.html.md) | Next: [New Hashing Algorithm for Passwords](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/new-hashing-algorithm-for-passwords/index.html.md)
