PHP code example of secudoc / php-liboqs

1. Go to this page and download the library: Download secudoc/php-liboqs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

secudoc / php-liboqs example snippets



use OQS\KEM;

// Pick an algorithm supported by your liboqs build:
$alg = defined('OQS\\KEM::ALG_ML_KEM_768') ? OQS\KEM::ALG_ML_KEM_768 : OQS\KEM::ALG_KYBER768;

[$pk, $sk] = KEM::keypair($alg);
[$ct, $ss1] = KEM::encapsulate($alg, $pk);
$ss2 = KEM::decapsulate($alg, $ct, $sk);

assert(hash_equals($ss1, $ss2));

// If you need text-safe values:
echo base64_encode($ct), "\n", base64_encode($ss1), "\n";

  print_r(OQS\KEM::algorithms());
  print_r(OQS\Signature::algorithms());
  
bash
sudo pie install secudoc/php-liboqs
bash
/php/bin/phpize
./configure --with-php-config=/php/bin/php-config --with-oqs
make -j$(nproc)
sudo make install
echo "extension=oqs.so" | sudo tee /etc/php/<ver>/mods-available/oqs.ini
sudo phpenmod oqs
php -m | grep oqs
bash
/php/php-8.5/bin/phpize
./configure --with-php-config=/php/php-8.5/bin/php-config --with-oqs=/usr/local
make -j$(nproc) && sudo make install