Site icon Cody Paste

Encrypt decrypt in CI4 – CodeIgniter 4

To pass an encrypted value in a URL and decrypt it in CodeIgniter 4 (CI4), you can use the Encryption library provided by CI4. Here’s how to implement this:


1. Configure Encryption in CI4

Ensure that the encryption service is properly set up. Open the app/Config/Encryption.php file and configure it:

Replace your-encryption-key with a strong random key. You can generate one using bin2hex(random_bytes(32)) in PHP.

 

2. Encrypt the Value

Use CI4’s encrypter() helper to encrypt the value before adding it to the URL:

 

3. Decrypt the Value

Retrieve and decrypt the value in your controller:

 

 

4. Example Flow

Exit mobile version