phpcodeigniter-3libsodium

Include and use sodium AES 256 encryption in codeigniter3


My current project built on codeigniter3 and PHP7.4 . Now i have a requirement to add sodium AES 256 encryption in my project. I have checked most of the articles on sodium encryption. As my research sodium included in codeigniter4. But moving from codeigniter3 to codeigniter4 needs a lot of work and it was a live project.

So i want to include sodium encryption and use in codeigniter3. I have google it and tried many of the articles but not found correct process to include sodium encryption in codeigniter3.

Can anyone have experience on this. Please provide some info on this.

Thanks in Advance.


Solution

  • PHP by default supports sodium encryption. No need to install or include any separate libraries.

    I also worked with codeigniter3. It will support dont worry. No need to migrate to codeigniter4.

    find the bellow code for example

    Note : ARGON2ID supports Above PHP 7.4 version only

    For create encrypted password:

    <?php
    $plaintext = 'echo2022";
    $salt = "yoursalt";
    $plaintextsecured = hash_hmac("sha256", $plaintext, $salt);
    $password_argon = bin2hex(password_hash($plaintextsecured, PASSWORD_ARGON2ID));
    echo $password_argon;
    ?>
    

    For verify password :

    <?php
    $salt = "yoursalt";
    $plaintext = 'echo2022';
    $plaintextsecured = hash_hmac("sha256", $plaintext, $salt);
    if(password_verify($plaintextsecured, hex2bin($password_argon))) {
       return true;
    } else {
       return false;
    }