![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
- C++11 compatible compiler
- CMake 3.10+
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)
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:
- Create cmake configuration file for target dependency
1 cmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR)
3 project ("@VIRGIL_DEPENDS_PACKAGE_NAME@-depends")
5 include (ExternalProject)
7 # Configure additional CMake parameters
8 file (WRITE "@VIRGIL_DEPENDS_ARGS_FILE@"
9 "set (ENABLE_TESTING OFF CACHE INTERNAL \"\")\n"
10 "set (INSTALL_EXT_LIBS ON CACHE INTERNAL \"\")\n"
11 "set (INSTALL_EXT_HEADERS ON CACHE INTERNAL \"\")\n"
12 "set (UCLIBC @UCLIBC@ CACHE INTERNAL \"\")\n"
15 ExternalProject_Add (${PROJECT_NAME}
16 DOWNLOAD_DIR "@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@"
17 URL "https://github.com/VirgilSecurity/sdk-cpp/archive/v5.0.0.tar.gz"
18 URL_HASH SHA1=<PUT_PACKAGE_HASH_HERE>
19 PREFIX "@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@"
20 CMAKE_ARGS "@VIRGIL_DEPENDS_CMAKE_ARGS@"
23 add_custom_target ("${PROJECT_NAME}-build" ALL COMMENT "Build package ${PROJECT_NAME}")
24 add_dependencies ("${PROJECT_NAME}-build" ${PROJECT_NAME})
- In the project just put
1 include (virgil_depends)
4 PACKAGE_NAME "virgil_sdk"
5 CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dir_to_config_file_from_step_1"
8 virgil_find_package (virgil_sdk)
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>
auto crypto = std::make_shared<Crypto>();
auto keyPair = crypto->generateKeyPair();
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;
auto messageToEncrypt = "Hello, Bob!";
auto dataToEncrypt = VirgilByteArrayUtils::stringToBytes(messageToEncrypt);
auto future = cardManager.searchCards("Bob");
auto bobCards = future.get();
auto bobRelevantCardsPublicKeys = std::vector<PublicKey>();
for (auto& card : bobCards)
bobRelevantCardsPublicKeys.push_back(card.publicKey());
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>
auto future = cardManager.searchCards("Alice");
auto aliceCards = future.get();
auto aliceRelevantCardsPublicKeys = std::vector<PublicKey>();
for (auto& card : aliceCards)
aliceRelevantCardsPublicKeys.push_back(card.publicKey());
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.