Virgil SDK allows developers to get up and running with Virgil API quickly and add full end-to-end (E2EE) security to their existing digital solutions to become HIPAA and GDPR compliant and more.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ci
cmake
docs
ext
include/virgil/sdk
src/virgil/sdk
tests
utils
.clang-format
.gitignore
.travis.yml
CMakeLists.txt
ChangeLog
Doxyfile.in
LICENSE
README.md
VERSION
logo.png

README.md

Virgil Security C++ SDK

Build Status Documentation Doxygen GitHub license

Introduction | SDK Features | Installation | Usage Examples | Docs | 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

  • C++11 compatible compiler
  • CMake 3.10+

CMake

Virgil SDK can be integrated using CMake in different ways:

Add downloaded sources as subdirectory

add_subdirectory (<PATH_TO_DEPENDENCIES>/sdk-cpp sdk-cpp)

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 an in-house dependency loader based on pure CMake features.

Usage:

  • Create cmake configuration file for target dependency
cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR)

project ("@VIRGIL_DEPENDS_PACKAGE_NAME@-depends")

include (ExternalProject)

# Configure additional CMake parameters
file (WRITE "@VIRGIL_DEPENDS_ARGS_FILE@"
  "set (ENABLE_TESTING OFF CACHE INTERNAL \"\")\n"
  "set (INSTALL_EXT_LIBS ON CACHE INTERNAL \"\")\n"
  "set (INSTALL_EXT_HEADERS ON CACHE INTERNAL \"\")\n"
  "set (UCLIBC @UCLIBC@ CACHE INTERNAL \"\")\n"
)

ExternalProject_Add (${PROJECT_NAME}
  DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@"
  URL "https://github.com/VirgilSecurity/sdk-cpp/archive/v5.0.0.tar.gz"
  URL_HASH SHA1=<PUT_PACKAGE_HASH_HERE>
  PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@"
  CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@"
)

add_custom_target ("${PROJECT_NAME}-build" ALL COMMENT "Build package ${PROJECT_NAME}")
add_dependencies ("${PROJECT_NAME}-build" ${PROJECT_NAME})
  • In the project, add the following code
include (virgil_depends)

virgil_depends (
  PACKAGE_NAME "virgil_sdk"
  CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dir_to_config_file_from_step_1"
)

virgil_find_package (virgil_sdk)

Usage Examples

Before you start practicing with the usage examples, make sure that the SDK is configured. Check out our SDK configuration guides for more details.

Generate and publish a User's Card with their Public Key on the Virgil Cards Service

Use the following lines of code to create and publish a user's Card (similar to a business card, this Card contains their Public Key) on the Virgil Cards Service:

#include <virgil/sdk/cards/CardManager.h>

using virgil::sdk::crypto::Crypto;
using virgil::sdk::cards::CardManager;

// 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 allows you to 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 the recipient's Card from the Virgil Cards Services. The Recipient's Card contains a Public Key with which we will encrypt the data and verify a signature.

#include <virgil/sdk/cards/CardManager.h>

using virgil::sdk::cards::CardManager;
using virgil::sdk::crypto::keys::PublicKey;
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 have received the signed and encrypted message, they can decrypt it with their own Private Key and verify the signature with the Sender's Card:

#include <virgil/sdk/cards/CardManager.h>

using virgil::sdk::cards::CardManager;
using virgil::sdk::crypto::keys::PublicKey;

// 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);

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 configure your application first. By default, the SDK will attempt to look for Virgil-specific settings in your application but you can customize those during the SDK configuration.

License

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

Support

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

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

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