Qzich / virgil-sdk-php

Virgil PHP SDKs for working with Virgil Keys services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Virgil Security PHP SDK

Latest Version on Packagist Total Downloads GitHub license

Introduction | SDK Features | Installation | Usage Examples | Docs | Support | SDK V4

Virgil Security provides a set of APIs for adding security to any application. In a few simple steps you can encrypt communication, securely store data, provide passwordless login, and ensure data integrity.

The Virgil SDK allows developers to get up and running with Virgil API quickly and add full end-to-end security to their existing digital solutions to become HIPAA and GDPR compliant and more.

SDK Features

Installation

The Virgil SDK is provided as a package named virgil/sdk. The package is distributed via Composer package management system.

The package is available for PHP version 5.6 and newer.

Installing the package using Package Manager Console:

$ composer require virgil/sdk

Crypto library notice

In order to support cipher operations upon your data there is must be installed crypto library also. We supply Virgil SDK with own implementation of cypto intefaces that can be easyly used by everyone. Just require it as a package:

$ composer require virgil/crypto

Be aware this package requires installed php virgil crypto extension ext-virgil_crypto_php.

Also there is avaliable setup your own Crypto library inside of the SDK

Using external crypto library (c++)

If you decide to use virgil/crypto package there is needs to install php virgil crypto extension ext-virgil_crypto_php as one of dependency otherwise you will get the requested PHP extension virgil_crypto_php is missing from your system error during composer install. Download proper extension package for your platform from cdn like virgil-crypto-2.3.0-php-5.6-linux-x86_64.tgz (highly recommended using latest version) and install. Unfortunately PHP extensions installation is out of this topic but you can find a lot of public information about it.

Usage Examples

Generate and publish user's Cards with Public Keys inside on Cards Service

Use the following lines of code to create and publish a user's Card with Public Key inside on Virgil Cards Service:

use Virgil\CryptoImpl;
use Virgil\Sdk;

$crypto = new CryptoImpl\VirgilCrypto();

// generate a key pair
$keyPair = $crypto->generateKeys();

// save a private key into key storage
$privateKeyStorage->store($keyPair->PrivateKey(), 'Alice');

// publish user's on the Cards Service
$card = $cardManager->publishCard(
    Sdk\CardParams::create(
        [
            Sdk\CardParams::PublicKey  => $keyPair->PublicKey(),
            Sdk\CardParams::PrivateKey => $keyPair->PrivateKey(),
        ]
    )
);

Sign then encrypt data

Virgil SDK lets you use a user's Private key and his or her Cards to sign, then encrypt any kind of data.

In the following example, we load a Private Key from a customized Key Storage and get recipient's Card from the Virgil Cards Services. Recipient's Card contains a Public Key on which we will encrypt the data and verify a signature.

use Virgil\CryptoImpl;
use Virgil\Sdk;

// prepare a message
$dataToEncrypt = 'Hello, Bob!';

// prepare a user's private key
$alicePrivateKeyEntry = $privateKeyStorage->load('Alice');

// using cardManager search for Bob's cards on Cards Service
$cads = $cardManager->searchCards('Bob');

$bobRelevantCardsPublicKeys = array_map(
    function (Sdk\Card $card) {
        return $card->getPublicKey();
    },
    $cads
);


// sign a message with a private key then encrypt using Bob's public keys
$encryptedData = $crypto->signThenEncrypt(
    $dataToEncrypt,
    $alicePrivateKeyEntry->getPrivateKey(),
    $bobRelevantCardsPublicKeys
);

Decrypt then verify data

Once the Users receive the signed and encrypted message, they can decrypt it with their own Private Key and verify signature with a Sender's Card:

use Virgil\CryptoImpl;
use Virgil\Sdk;

// prepare a user's private key
$bobPrivateKeyEntry = $privateKeyStorage->load('Bob');

// using cardManager search for Alice's cards on Cards Service
$cards = $cardManager->searchCards('Alice');

// using cardManager search for Alice's cards on Cards Service
$aliceRelevantCardsPublicKeys = array_map(
    function (Sdk\Card $card) {
        return $card->getPublicKey();
    },
    $cads
);

// decrypt with a private key and verify using one of Alice's public keys
$decryptedData = $crypto->decryptThenVerify(
    $encryptedData,
    $bobPrivateKeyEntry->getPrivateKey(),
    $aliceRelevantCardsPublicKeys
);

Docs

Virgil Security has a powerful set of APIs, and the documentation below can get you started today.

In order to use the Virgil SDK with your application, you will need to first configure your application. By default, the SDK will attempt to look for Virgil-specific settings in your application but you can change it during SDK configuration.

License

This library is released under the 3-clause BSD License.

Support

Our developer support team is here to help you.

You can find us on Twitter or send us email support@VirgilSecurity.com.

Also, get extra help from our support team on Slack.

SDK-V4

https://github.com/VirgilSecurity/virgil-sdk-php/tree/v4

About

Virgil PHP SDKs for working with Virgil Keys services

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:PHP 100.0%