1. Go to this page and download the library: Download gmtls/openssl-crypto-kit 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/ */
gmtls / openssl-crypto-kit example snippets
use GmTLS\CryptoKit\EC;
use GmTLS\CryptoKit\RSA;
$key = EC::createKey('secp521r1', 'password');
$key = RSA::createKey(1024, 'password');
use GmTLS\CryptoKit\KeypairLoader;
KeypairLoader::fromPrivateKeyFile(realpath('private.pem'), 'password');
KeypairLoader::fromPublicKeyFile(realpath('public.pem'));
KeypairLoader::fromFile(realpath('key.pem'), 'password');
use GmTLS\CryptoKit\Concerns\AsymmetricKey;
use GmTLS\CryptoKit\Keypair;
use GmTLS\CryptoKit\Crypto\PrivateKey;
use GmTLS\CryptoKit\Crypto\PublicKey;
use RuntimeException;
class DSA extends AsymmetricKey
{
public static function createKey(): Keypair
{
throw new RuntimeException('Direct generation of DSA keys is not supported');
}
public function getPublicKey(): PublicKey
{
return new PublicKey(new Keypair(
publicKey: $this->getKeypair()->getPublicKey()
));
}
public function getPrivateKey(): PrivateKey
{
return new PrivateKey(new Keypair(
privateKey: $this->getKeypair()->getPrivateKey(),
publicKey: $this->getKeypair()->getPublicKey(),
passphrase: $this->getKeypair()->getPassphrase(),
));
}
}
use GmTLS\CryptoKit\CryptoKit;
use GmTLS\CryptoKit\Keypair;
use GmTLS\CryptoKit\KeypairLoader;
CryptoKit::extend(OPENSSL_KEYTYPE_DSA, function (Keypair $keypair) {
return new DSA($keypair);
});