Virgil Security C++ SDK
Virgil Security C++ SDK Documentation

![Build Status](https://travis-ci.com/VirgilSecurity/sdk-cpp.svg?branch=master) ![Documentation Doxygen](https://img.shields.io/badge/docs-doxygen-blue.svg) ![GitHub license](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)

Introduction | SDK Features | Installation | Usage Examples | Support

Introduction

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

Requirements

CMake

Virgil SDK can be integrated using CMake in the different ways

Add downloaded sources as subdirectory

1 add_subdirectory (<PATH_TO_DEPENDENCIES>/sdk-cpp sdk-cpp)
2 
3 target_link_libraries (${PROJECT_NAME} virgil_sdk)

Use custom CMake util

You can find file called virgil_depends_local.cmake at sdk-cpp/cmake/utils. This is in-house dependency loader based on pure CMake features.

Usage:

Usage Examples

Before start practicing with the usage examples be sure that the SDK is configured. Check out our SDK configuration guides for more information.

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:

#include <virgil/sdk/cards/CardManager.h>
// use Virgil Crypto
auto crypto = std::make_shared<Crypto>();
// generate a key pair
auto keyPair = crypto->generateKeyPair();
// publish card on Cards Service
auto future = cardManager.publishCard(keyPair.privateKey(), keyPair.publicKey());
auto card = future.get();

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.

#include <virgil/sdk/cards/CardManager.h>
using virgil::sdk::VirgilByteArrayUtils;
// prepare a message
auto messageToEncrypt = "Hello, Bob!";
auto dataToEncrypt = VirgilByteArrayUtils::stringToBytes(messageToEncrypt);
// using cardManager search for Bob's cards on Cards Service
auto future = cardManager.searchCards("Bob");
auto bobCards = future.get();
auto bobRelevantCardsPublicKeys = std::vector<PublicKey>();
for (auto& card : bobCards)
bobRelevantCardsPublicKeys.push_back(card.publicKey());
// sign a message with a private key then encrypt using Bob's public keys
auto encryptedData = crypto->signThenEncrypt(dataToEncrypt, alicePrivateKey, 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:

#include <virgil/sdk/cards/CardManager.h>
// using cardManager search for Alice's cards on Cards Service
auto future = cardManager.searchCards("Alice");
auto aliceCards = future.get();
auto aliceRelevantCardsPublicKeys = std::vector<PublicKey>();
for (auto& card : aliceCards)
aliceRelevantCardsPublicKeys.push_back(card.publicKey());
// decrypt with a private key and verify using one of Alice's public keys
auto decryptedData = crypto->decryptThenVerify(encryptedData, bobPrivateKey, aliceRelevantCardsPublicKeys);

License

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

Support

Our developer support team is here to help you. Find out more information on our Help Center.

You can find us on Twitter or send us email suppo.nosp@m.rt@V.nosp@m.irgil.nosp@m.Secu.nosp@m.rity..nosp@m.com.

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