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.
- communicate with Virgil Cards Service
- manage users' Public Keys
- store private keys in secure local storage
- use Virgil Crypto library
- use your own Crypto
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
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
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.
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(),
]
)
);
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
);
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
);
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.
- Configure the SDK documentation
- Setup authentication to make API calls to Virgil Services
- Setup Card Manager to manage user's Public Keys
- Setup Card Verifier to verify signatures inside of user's Card
- Setup Key storage to store Private Keys
- Setup your own Crypto library inside of the SDK
- More usage examples
- Create & publish a Card that has a Public Key on Virgil Cards Service
- Search user's Card by user's identity
- Get user's Card by its ID
- Use Card for crypto operations
- Reference API
This library is released under the 3-clause BSD License.
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.