PHP code example of johnhenryspike / kalkancrypt

1. Go to this page and download the library: Download johnhenryspike/kalkancrypt 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/ */

    

johnhenryspike / kalkancrypt example snippets


// init KeyStore (default storage type PKCS12)
$keyStore = KeyStore::load('/path/to/keyStore.p12', 'password');
//init Chain 
$chain = Chain::init($this->keyStore)->fromSystem();
//init Provider with chain, sign data and return signed string
return Provider::init($chain)->signData("Hello world", SignFlag::SIGN_CMS | SignFlag::OUT_PEM);

$keyStore = KeyStore::load('/path/to/keyStore.p12', 'password');
$collection = new CertCollection();
$collection->addItem(Certificate::loadFromPath('/path/to/nca.cer'));
$collection->addItem(Certificate::loadFromPath('/path/to/root.cer'));
$chain = Chain::init($this->keyStore)->fromCollection($collection);
return Provider::init($chain)->signData("Hello world", SignFlag::SIGN_CMS | SignFlag::OUT_PEM);

$keyStore = KeyStore::load('/path/to/keyStore.p12', 'password');
$chain  = Chain::init($keyStore)->fromAuthInfo();
return Provider::init($chain)->signData("Hello world", SignFlag::SIGN_CMS | SignFlag::OUT_PEM);

$adapter = Adapter::getInstance();

$adapter -> loadKeyStore( Adapter::KCST_PKCS12, '/path/to/keyStore.p12', 'password');

// use if CA certs not registered in system
// $adapter->loadCertFromFile(Adapter::KC_CERT_INTERMEDIATE, '/path/to/nca_gost.pem');
// $adapter->loadCertFromFile(Adapter::KC_CERT_CA, '/path/to/root_gost.pem');

return $a->signData( "Hello World", 
    Adapter::KC_SIGN_CMS | 
    Adapter::KC_IN_PEM   | 
    Adapter::KC_OUT_PEM 
);

$provider = Provider::init(
    Chain::init(
        KeyStore::load('/path/to/keyStore.p12', 'password')
    )->fromAuthInfo()
);

$client = new WsseClient($provider, [
    "location" => "http://192.168.1.1/bip-sync-wss-gost/",
    "uri" => "http://bip.bee.kz/SyncChannel/v10/Types",
    'proxy_host' => '127.0.0.1',
    'proxy_port' => 80
]);
return $client->SendMessage(new \SoapVar('<mydata>Hello World</mydata>', XSD_ANYXML));