All Projects → VirgilSecurity → virgil-sdk-cpp

VirgilSecurity / virgil-sdk-cpp

Licence: other
Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
shell
77523 projects

Projects that are alternatives of or similar to virgil-sdk-cpp

virgil-sdk-x
Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
Stars: ✭ 27 (+50%)
Mutual labels:  pki, hipaa, gdpr, end-to-end-encryption
Virgil Crypto Php
Virgil PHP Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
Stars: ✭ 22 (+22.22%)
Mutual labels:  cryptography, encryption, gdpr, end-to-end-encryption
virgil-sdk-net
Virgil Core SDK allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions to become HIPAA and GDPR compliant and more.
Stars: ✭ 16 (-11.11%)
Mutual labels:  encryption, pki, gdpr, end-to-end-encryption
Demo Twilio Backend Nodejs
A sample backend that demonstrates how to generate a Virgil JWT and Twilio token used for authentication with the Virgil and Twilio services
Stars: ✭ 128 (+611.11%)
Mutual labels:  cryptography, encryption, end-to-end-encryption
Awesome Virgil
Key Management and Crypto Building Block for your App or Device.
Stars: ✭ 146 (+711.11%)
Mutual labels:  cryptography, gdpr, end-to-end-encryption
virgil-crypto-javascript
Virgil JavaScript Crypto Library is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant.
Stars: ✭ 31 (+72.22%)
Mutual labels:  hipaa, gdpr, end-to-end-encryption
Darkwire.io
End-to-end encrypted instant web chat
Stars: ✭ 594 (+3200%)
Mutual labels:  cryptography, encryption, end-to-end-encryption
virgil-crypto
Virgil Crypto is a high-level cryptographic library that allows you to perform all necessary operations for secure storing and transferring data and everything required to become HIPAA and GDPR compliant. Crypto Library is written in C++, suitable for mobile and server platforms and supports bindings with: Swift, Obj-C, Java (Android), С#/.NET, …
Stars: ✭ 74 (+311.11%)
Mutual labels:  hipaa, gdpr, end-to-end-encryption
Awesome Iam
👤 Identity and Access Management Knowledge for Cloud Platforms
Stars: ✭ 186 (+933.33%)
Mutual labels:  cryptography, pki, gdpr
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+1105.56%)
Mutual labels:  cryptography, encryption
Helib
HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
Stars: ✭ 2,749 (+15172.22%)
Mutual labels:  cryptography, encryption
Openssl
TLS/SSL and crypto library
Stars: ✭ 17,157 (+95216.67%)
Mutual labels:  cryptography, encryption
Routinator
An RPKI Validator written in Rust
Stars: ✭ 215 (+1094.44%)
Mutual labels:  cryptography, pki
Pgsodium
Modern cryptography for PostgreSQL using libsodium.
Stars: ✭ 202 (+1022.22%)
Mutual labels:  cryptography, encryption
Sqleet
SQLite3 encryption that sucks less
Stars: ✭ 244 (+1255.56%)
Mutual labels:  cryptography, encryption
Encrypt
🔒 A set of high-level APIs over PointyCastle for two-way cryptography.
Stars: ✭ 199 (+1005.56%)
Mutual labels:  cryptography, encryption
havengrc
☁️Haven GRC - easier governance, risk, and compliance 👨‍⚕️👮‍♀️🦸‍♀️🕵️‍♀️👩‍🔬
Stars: ✭ 83 (+361.11%)
Mutual labels:  hipaa, gdpr
Tenseal
A library for doing homomorphic encryption operations on tensors
Stars: ✭ 197 (+994.44%)
Mutual labels:  cryptography, encryption
parse-hipaa
HIPAA & GDPR compliant ready parse-server with postgres/mongo, parse-hipaa-dashboard. Compatible with ParseCareKit
Stars: ✭ 74 (+311.11%)
Mutual labels:  hipaa, gdpr
wormhole-william-mobile
End-to-end encrypted file transfer for Android. An Android Magic Wormhole client.
Stars: ✭ 57 (+216.67%)
Mutual labels:  encryption, end-to-end-encryption

Virgil Core SDK C++

Build Status Documentation Doxygen GitHub license

Introduction | SDK Features | Installation | Configure SDK | 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 communications, securely store data, and ensure data integrity. Virgil Security products are available for desktop, embedded (IoT), mobile, cloud, and web applications in a variety of modern programming languages.

The Virgil Core SDK is a low-level library that allows developers to get up and running with Virgil Cards Service API quickly and add end-to-end security to their new or existing digital solutions.

In case you need additional security functionality for multi-device support, group chats and more, try our high-level Virgil E3Kit framework.

SDK Features

Installation

The Virgil Core SDK С++ is provided as a package named virgil_sdk.

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>/virgil-sdk-cpp virgil-sdk-cpp)

target_link_libraries (${PROJECT_NAME} virgil_sdk)

Use custom CMake util

You can find еру file called virgil_depends_local.cmake at virgil-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/virgil-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)

Configure SDK

This section contains guides on how to set up Virgil Core SDK modules for authenticating users, managing Virgil Cards and storing private keys.

Set up authentication

Set up user authentication with tokens that are based on the JSON Web Token standard with some Virgil modifications.

In order to make calls to Virgil Services (for example, to publish user's Card on Virgil Cards Service), you need to have a JSON Web Token ("JWT") that contains the user's identity, which is a string that uniquely identifies each user in your application.

Credentials that you'll need:

Parameter Description
App ID ID of your Application at Virgil Dashboard
App Key ID A unique string value that identifies your account at the Virgil developer portal
App Key A Private Key that is used to sign API calls to Virgil Services. For security, you will only be shown the App Key when the key is created. Don't forget to save it in a secure location for the next step

Set up JWT provider on Client side

Use these lines of code to specify which JWT generation source you prefer to use in your project:

#include <virgil/sdk/jwt/providers/CachingJwtProvider.h>

using virgil::sdk::jwt::TokenContext;
using virgil::sdk::jwt::providers::CachingJwtProvider;

// Get generated token from server-side
auto authenticatedQueryToServerSide = [&](const TokenContext& context) {
    std::promise<std::string> p;
    p.set_value("<TOKEN_FETCHED_FROM_SERVER>");

    return p.get_future();
};

// Setup AccessTokenProvider
auto provider = std::make_shared<CachingJwtProvider>(authenticatedQueryToServerSide);

Generate JWT on Server side

Next, you'll need to set up the JwtGenerator and generate a JWT using the Virgil SDK.

Here is an example of how to generate a JWT:

#include <virgil/sdk/jwt/JwtGenerator.h>
#include <virgil/sdk/crypto/Crypto.h>

using virgil::sdk::jwt::JwtGenerator;
using virgil::sdk::VirgilBase64;
using virgil::sdk::crypto::Crypto;    

// App Key (you got this Key at Virgil Dashboard)
auto appKeyBase64 = "MIGhMF0GCSqGSIb3DQEFDTBQMC8GCSqGSIb3DQEFDDAiBBC7Sg/DbNzhJ/uakTvafUMoAgIUtzAKBggqhkiG9w0CCjAdBglghkgBZQMEASoEEDunQ1yhWZoKaLaDFgjpxRwEQAFdbC8e6103lJrUhY9ahyUA8+4rTJKZCmdTlCDPvoWH/5N5kxbOvTtbxtxevI421z3gRbjAtoWkfWraSLD6gj0=";
auto privateKeyData = VirgilBase64::decode(appKeyBase64);

// Crypto library imports a private key into a necessary format
auto crypto = std::shared_ptr<Crypto>();
auto appKey = crypto->importPrivateKey(privateKeyData);

// use your App Credentials you got at Virgil Dashboard:
auto appId = "be00e10e4e1f4bf58f9b4dc85d79c77a"; // App ID
auto appKeyId = "70b447e321f3a0fd"; // App Key ID
int ttl = 60 * 60 * 24; // 1 hour (JWT's lifetime)

// setup JWT generator with necessary parameters:
auto jwtGenerator = JwtGenerator(appKey, appKeyId, crypto, appId, ttl);

// generate JWT for a user
// remember that you must provide each user with his unique JWT
// each JWT contains unique user's identity (in this case - Alice)
// identity can be any value: name, email, some id etc.
auto identity = "Alice";
auto aliceJwt = jwtGenerator.generateToken(identity);

// as result you get users JWT, it looks like this: "eyJraWQiOiI3MGI0NDdlMzIxZjNhMGZkIiwidHlwIjoiSldUIiwiYWxnIjoiVkVEUzUxMiIsImN0eSI6InZpcmdpbC1qd3Q7dj0xIn0.eyJleHAiOjE1MTg2OTg5MTcsImlzcyI6InZpcmdpbC1iZTAwZTEwZTRlMWY0YmY1OGY5YjRkYzg1ZDc5Yzc3YSIsInN1YiI6ImlkZW50aXR5LUFsaWNlIiwiaWF0IjoxNTE4NjEyNTE3fQ.MFEwDQYJYIZIAWUDBAIDBQAEQP4Yo3yjmt8WWJ5mqs3Yrqc_VzG6nBtrW2KIjP-kxiIJL_7Wv0pqty7PDbDoGhkX8CJa6UOdyn3rBWRvMK7p7Ak"
// you can provide users with JWT at registration or authorization steps
// Send a JWT to client-side
auto jwtString = aliceJwt.stringRepresentation();

For this subsection we've created a sample backend that demonstrates how you can set up your backend to generate the JWTs. To set up and run the sample backend locally, head over to your GitHub repo of choice:

Node.js | Golang | PHP | Java | Python and follow the instructions in README.

Set up Card Verifier

Virgil Card Verifier helps you automatically verify signatures of a user's Card, for example when you get a Card from Virgil Cards Service.

By default, VirgilCardVerifier verifies only two signatures - those of a Card owner and Virgil Cards Service.

Set up VirgilCardVerifier with the following lines of code:

#include <virgil/sdk/cards/verification/VirgilCardVerifier.h>

using virgil::sdk::VirgilBase64;
using virgil::sdk::cards::verification::VirgilCardVerifier;
using virgil::sdk::cards::verification::VerifierCredentials;
using virgil::sdk::cards::verification::Whitelist;
using virgil::sdk::crypto::Crypto;

auto crypto = std::shared_ptr<Crypto>();

auto publicKeyData = VirgilBase64::decode(publicKeyStr);
auto yourBackendVerifierCredentials = VerifierCredentials("YOUR_BACKEND", publicKeyData);

auto yourBackendWhitelist = Whitelist({ yourBackendVerifierCredentials });

auto cardVerifier = VirgilCardVerifier(crypto, { yourBackendWhitelist });

Set up Card Manager

This subsection shows how to set up a Card Manager module to help you manage users' public keys.

With Card Manager you can:

  • specify an access Token (JWT) Provider.
  • specify a Card Verifier used to verify signatures of your users, your App Server, Virgil Services (optional).

Use the following lines of code to set up the Card Manager:

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

using virgil::sdk::cards::CardManager;

// initialize cardManager and specify accessTokenProvider, cardVerifier
auto cardManager = CardManager(crypto, accessTokenProvider, cardVerifier);

Usage Examples

Before you start practicing with the usage examples, make sure that the SDK is configured. See the Configure SDK section for more information.

Generate and publish Virgil Cards at Cards Service

Use the following lines of code to create a user's Card with a public key inside and publish it at 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 Core SDK allows you to use a user's private key and their Virgil Cards to sign and 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 Service. Recipient's Card contains a public key which we will use to 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 data and verify signature

Once the user receives 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);

Get Card by its ID

Use the following lines of code to get a user's card from Virgil Cloud by its ID:

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

using virgil::sdk::cards::CardManager;

// using cardManager get a user's card from the Cards Service
auto getFuture = cardManager.getCard("f4bf9f7fcbedaba0392f108c59d8f4a38b3838efb64877380171b54475c2ade8");
auto card = getFuture.get()

Get Card by user's identity

For a single user, use the following lines of code to get a user's Card by a user's identity:

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

using virgil::sdk::cards::CardManager;

// using cardManager search for user's cards on Cards Service
auto searchFuture = cardManager.searchCards("Bob");
auto cards = searchFuture.get();

Docs

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

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 [email protected].

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].