1. Go to this page and download the library: Download guycalledseven/php-ext-oqs 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/ */
guycalledseven / php-ext-oqs example snippets
// Example of best practice
[$ct, $shared_secret] = $kem->encap($pk);
// Now, derive a 32-byte AES key and a 16-byte IV from the shared secret
$keying_material = hash_hkdf('sha256', $shared_secret, 48, 'my-app-encryption', 'some-salt');
$aes_key = substr($keying_material, 0, 32);
$iv = substr($keying_material, 32, 16);
use Oqs\Kem;
use Oqs\Sig;
// 1. Key Encapsulation (KEM) Example with ML-KEM
$kem = new Kem(Kem::ALG_ML_KEM_768);
// Generate a public/private key pair
[$publicKey, $secretKey] = $kem->keypair();
// A client encapsulates a secret against the public key,
// generating a ciphertext and a shared secret.
[$ciphertext, $sharedSecretA] = $kem->encap($publicKey);
// The server decapsulates the ciphertext with the secret key
// to derive the same shared secret.
$sharedSecretB = $kem->decap($ciphertext, $secretKey);
assert($sharedSecretA === $sharedSecretB);
echo "KEM shared secrets match!\n";
// IMPORTANT: The raw shared secret should be passed through a KDF
// like HKDF before being used as an encryption key.
$encryption_key = hash_hkdf('sha256', $sharedSecretA, 32, 'my-app-aes-key');
// 2. Digital Signature (SIG) Example with ML-DSA
$sig = new Sig(Sig::ALG_ML_DSA_65);
// Generate a signing key pair
[$signingPublicKey, $signingSecretKey] = $sig->keypair();
$message = "This is the message to sign.";
// Sign the message with the secret key
$signature = $sig->sign($message, $signingSecretKey);
// Verify the signature against the message and public key
$isValid = $sig->verify($message, $signature, $signingPublicKey);
assert($isValid === true);
echo "Signature is valid!\n";