### Install IPcrypt PHP Library using Composer Source: https://github.com/jedisct1/php-ipcrypt/blob/main/README.md This command adds the IPcrypt PHP library to your project as a dependency using Composer. It downloads the necessary files and updates your composer.json and composer.lock files. ```sh composer require jedisct1/ipcrypt ``` -------------------------------- ### Run PHPUnit Tests using Composer Source: https://github.com/jedisct1/php-ipcrypt/blob/main/README.md These commands are used for setting up dependencies and executing the test suite for the library. 'composer install' fetches project dependencies, and 'composer test' runs the PHPUnit tests defined in the project. ```sh composer install # Install dependencies composer test # Run PHPUnit tests ``` -------------------------------- ### Encrypt/Decrypt IP addresses using IpcryptNd PHP Source: https://github.com/jedisct1/php-ipcrypt/blob/main/README.md This PHP snippet illustrates the non-deterministic encryption mode using the IpcryptNd class. It shows how to generate a 16-byte key and demonstrates that encrypting the same IP multiple times produces different ciphertexts due to the use of random tweaks, while decryption successfully recovers the original IP. ```php use Ipcrypt\IpcryptNd; // Generate a random 16-byte key $key = IpcryptNd::generateKey(); $ip = '192.0.2.1'; // Each encryption produces a different result $encrypted1 = IpcryptNd::encrypt($ip, $key); // Uses random 8-byte tweak $encrypted2 = IpcryptNd::encrypt($ip, $key); // Different result echo $encrypted1 !== $encrypted2; // true // Both decrypt to the same IP $decrypted1 = IpcryptNd::decrypt($encrypted1, $key); $decrypted2 = IpcryptNd::decrypt($encrypted2, $key); echo $decrypted1 === $decrypted2; // true ``` -------------------------------- ### Encrypt/Decrypt IP addresses using IpcryptDeterministic PHP Source: https://github.com/jedisct1/php-ipcrypt/blob/main/README.md This PHP snippet demonstrates how to use the IpcryptDeterministic class for deterministic IP address encryption. It shows how to generate a 16-byte key and encrypt/decrypt both IPv4 and IPv6 addresses, emphasizing that the same input always yields the same output with the same key. ```php use Ipcrypt\IpcryptDeterministic; // Generate a random 16-byte key $key = IpcryptDeterministic::generateKey(); // Example with IPv4 $ipv4 = '192.0.2.1'; $encrypted = IpcryptDeterministic::encrypt($ipv4, $key); $decrypted = IpcryptDeterministic::decrypt($encrypted, $key); // Example with IPv6 $ipv6 = '2001:db8::1'; $encrypted = IpcryptDeterministic::encrypt($ipv6, $key); $decrypted = IpcryptDeterministic::decrypt($encrypted, $key); ``` -------------------------------- ### Encrypt/Decrypt IP addresses using IpcryptNdx PHP (XTS mode) Source: https://github.com/jedisct1/php-ipcrypt/blob/main/README.md This PHP snippet demonstrates the XTS-mode non-deterministic encryption using the IpcryptNdx class. It requires generating a 32-byte key and shows that, like IpcryptNd, repeated encryptions of the same IP result in different outputs, while decryption correctly recovers the original IP. ```php use Ipcrypt\IpcryptNdx; // Generate a random 32-byte key (two AES-128 keys) $key = IpcryptNdx::generateKey(); $ip = '192.0.2.1'; // Each encryption produces a different result $encrypted1 = IpcryptNdx::encrypt($ip, $key); // Uses random 16-byte tweak $encrypted2 = IpcryptNdx::encrypt($ip, $key); // Different result echo $encrypted1 !== $encrypted2; // true // Both decrypt to the same IP $decrypted1 = IpcryptNdx::decrypt($encrypted1, $key); $decrypted2 = IpcryptNdx::decrypt($encrypted2, $key); echo $decrypted1 === $decrypted2; // true ``` -------------------------------- ### Check and Fix Code Style using Composer Source: https://github.com/jedisct1/php-ipcrypt/blob/main/README.md These Composer commands are used to ensure the codebase adheres to PSR-12 coding standards. 'composer cs' checks for violations, and 'composer cs-fix' attempts to automatically correct style issues. ```sh composer cs # Check code style composer cs-fix # Automatically fix code style issues ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.