{"id":19198467,"url":"https://github.com/virgilsecurity/virgil-sdk-cpp","last_synced_at":"2025-07-04T06:34:01.743Z","repository":{"id":32037936,"uuid":"35609382","full_name":"VirgilSecurity/virgil-sdk-cpp","owner":"VirgilSecurity","description":"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.","archived":false,"fork":false,"pushed_at":"2020-05-18T10:19:01.000Z","size":2412,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-09T01:17:00.033Z","etag":null,"topics":["cryptography","encryption","end-to-end-encryption","gdpr","hipaa","pki","sdk"],"latest_commit_sha":null,"homepage":"https://virgilsecurity.com/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VirgilSecurity.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-14T12:15:05.000Z","updated_at":"2021-10-13T01:45:44.000Z","dependencies_parsed_at":"2022-08-24T14:23:04.124Z","dependency_job_id":null,"html_url":"https://github.com/VirgilSecurity/virgil-sdk-cpp","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/VirgilSecurity/virgil-sdk-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VirgilSecurity","download_url":"https://codeload.github.com/VirgilSecurity/virgil-sdk-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263462960,"owners_count":23470445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","encryption","end-to-end-encryption","gdpr","hipaa","pki","sdk"],"created_at":"2024-11-09T12:22:12.127Z","updated_at":"2025-07-04T06:34:01.701Z","avatar_url":"https://github.com/VirgilSecurity.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Virgil Core SDK C++\n\n[![Build Status](https://travis-ci.com/VirgilSecurity/virgil-sdk-cpp.svg?branch=master)](https://travis-ci.com/VirgilSecurity/virgil-sdk-cpp)\n[![Documentation Doxygen](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://VirgilSecurity.github.io/virgil-sdk-cpp)\n[![GitHub license](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://raw.githubusercontent.com/VirgilSecurity/virgil-sdk-cpp/release/LICENSE)\n\n\n[Introduction](#introduction) | [SDK Features](#sdk-features) | [Installation](#installation) | [Configure SDK](#configure-sdk) | [Usage Examples](#usage-examples) | [Docs](#docs) | [Support](#support)\n\n## Introduction\n\n\u003ca href=\"https://developer.virgilsecurity.com/docs\"\u003e\u003cimg width=\"230px\" src=\"https://cdn.virgilsecurity.com/assets/images/github/logos/virgil-logo-red.png\" align=\"left\" hspace=\"10\" vspace=\"6\"\u003e\u003c/a\u003e [Virgil Security](https://virgilsecurity.com) 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.\n\nThe Virgil Core SDK is a low-level library that allows developers to get up and running with [Virgil Cards Service API](https://developer.virgilsecurity.com/docs/platform/api-reference/cards-service/) quickly and add end-to-end security to their new or existing digital solutions.\n\nIn case you need additional security functionality for multi-device support, group chats and more, try our high-level [Virgil E3Kit framework](https://github.com/VirgilSecurity/awesome-virgil#E3Kit).\n\n## SDK Features\n- Communicate with [Virgil Cards Service](https://developer.virgilsecurity.com/docs/platform/api-reference/cards-service/)\n- Manage users' public keys\n- Encrypt, sign, decrypt and verify data\n- Store private keys in secure local storage\n- Use [Virgil Crypto Library](https://github.com/VirgilSecurity/virgil-crypto)\n\n## Installation\n\nThe Virgil Core SDK С++ is provided as a package named virgil_sdk.\n\n#### Requirements\n\n- C++11 compatible compiler\n- CMake 3.10+\n\n### CMake\nVirgil SDK can be integrated using CMake in different ways:\n\n#### Add downloaded sources as subdirectory\n\n```cmake\nadd_subdirectory (\u003cPATH_TO_DEPENDENCIES\u003e/virgil-sdk-cpp virgil-sdk-cpp)\n\ntarget_link_libraries (${PROJECT_NAME} virgil_sdk)\n```\n\n#### Use custom CMake util\nYou can find еру file called *virgil_depends_local.cmake* at *virgil-sdk-cpp/cmake/utils*.\nThis is an in-house dependency loader based on pure CMake features.\n\nUsage:\n  - Create cmake configuration file for target dependency\n```cmake\ncmake_minimum_required (VERSION @CMAKE_VERSION@ FATAL_ERROR)\n\nproject (\"@VIRGIL_DEPENDS_PACKAGE_NAME@-depends\")\n\ninclude (ExternalProject)\n\n# Configure additional CMake parameters\nfile (WRITE \"@VIRGIL_DEPENDS_ARGS_FILE@\"\n  \"set (ENABLE_TESTING OFF CACHE INTERNAL \\\"\\\")\\n\"\n  \"set (INSTALL_EXT_LIBS ON CACHE INTERNAL \\\"\\\")\\n\"\n  \"set (INSTALL_EXT_HEADERS ON CACHE INTERNAL \\\"\\\")\\n\"\n  \"set (UCLIBC @UCLIBC@ CACHE INTERNAL \\\"\\\")\\n\"\n)\n\nExternalProject_Add (${PROJECT_NAME}\n  DOWNLOAD_DIR \"@VIRGIL_DEPENDS_PACKAGE_DOWNLOAD_DIR@\"\n  URL \"https://github.com/VirgilSecurity/virgil-sdk-cpp/archive/v5.0.0.tar.gz\"\n  URL_HASH SHA1=\u003cPUT_PACKAGE_HASH_HERE\u003e\n  PREFIX \"@VIRGIL_DEPENDS_PACKAGE_BUILD_DIR@\"\n  CMAKE_ARGS \"@VIRGIL_DEPENDS_CMAKE_ARGS@\"\n)\n\nadd_custom_target (\"${PROJECT_NAME}-build\" ALL COMMENT \"Build package ${PROJECT_NAME}\")\nadd_dependencies (\"${PROJECT_NAME}-build\" ${PROJECT_NAME})\n```\n  - In the project, add the following code\n```cmake\ninclude (virgil_depends)\n\nvirgil_depends (\n  PACKAGE_NAME \"virgil_sdk\"\n  CONFIG_DIR \"${CMAKE_CURRENT_SOURCE_DIR}/dir_to_config_file_from_step_1\"\n)\n\nvirgil_find_package (virgil_sdk)\n```\n\n## Configure SDK\n\nThis section contains guides on how to set up Virgil Core SDK modules for authenticating users, managing Virgil Cards and storing private keys.\n\n### Set up authentication\n\nSet up user authentication with tokens that are based on the [JSON Web Token standard](https://jwt.io/) with some Virgil modifications.\n\nIn 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.\n\nCredentials that you'll need:\n\n|Parameter|Description|\n|--- |--- |\n|App ID|ID of your Application at [Virgil Dashboard](https://dashboard.virgilsecurity.com)|\n|App Key ID|A unique string value that identifies your account at the Virgil developer portal|\n|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|\n\n#### Set up JWT provider on Client side\n\nUse these lines of code to specify which JWT generation source you prefer to use in your project:\n\n```cpp\n#include \u003cvirgil/sdk/jwt/providers/CachingJwtProvider.h\u003e\n\nusing virgil::sdk::jwt::TokenContext;\nusing virgil::sdk::jwt::providers::CachingJwtProvider;\n\n// Get generated token from server-side\nauto authenticatedQueryToServerSide = [\u0026](const TokenContext\u0026 context) {\n    std::promise\u003cstd::string\u003e p;\n    p.set_value(\"\u003cTOKEN_FETCHED_FROM_SERVER\u003e\");\n\n    return p.get_future();\n};\n\n// Setup AccessTokenProvider\nauto provider = std::make_shared\u003cCachingJwtProvider\u003e(authenticatedQueryToServerSide);\n```\n\n#### Generate JWT on Server side\n\nNext, you'll need to set up the `JwtGenerator` and generate a JWT using the Virgil SDK.\n\nHere is an example of how to generate a JWT:\n\n```cpp\n#include \u003cvirgil/sdk/jwt/JwtGenerator.h\u003e\n#include \u003cvirgil/sdk/crypto/Crypto.h\u003e\n\nusing virgil::sdk::jwt::JwtGenerator;\nusing virgil::sdk::VirgilBase64;\nusing virgil::sdk::crypto::Crypto;    \n\n// App Key (you got this Key at Virgil Dashboard)\nauto appKeyBase64 = \"MIGhMF0GCSqGSIb3DQEFDTBQMC8GCSqGSIb3DQEFDDAiBBC7Sg/DbNzhJ/uakTvafUMoAgIUtzAKBggqhkiG9w0CCjAdBglghkgBZQMEASoEEDunQ1yhWZoKaLaDFgjpxRwEQAFdbC8e6103lJrUhY9ahyUA8+4rTJKZCmdTlCDPvoWH/5N5kxbOvTtbxtxevI421z3gRbjAtoWkfWraSLD6gj0=\";\nauto privateKeyData = VirgilBase64::decode(appKeyBase64);\n\n// Crypto library imports a private key into a necessary format\nauto crypto = std::shared_ptr\u003cCrypto\u003e();\nauto appKey = crypto-\u003eimportPrivateKey(privateKeyData);\n\n// use your App Credentials you got at Virgil Dashboard:\nauto appId = \"be00e10e4e1f4bf58f9b4dc85d79c77a\"; // App ID\nauto appKeyId = \"70b447e321f3a0fd\"; // App Key ID\nint ttl = 60 * 60 * 24; // 1 hour (JWT's lifetime)\n\n// setup JWT generator with necessary parameters:\nauto jwtGenerator = JwtGenerator(appKey, appKeyId, crypto, appId, ttl);\n\n// generate JWT for a user\n// remember that you must provide each user with his unique JWT\n// each JWT contains unique user's identity (in this case - Alice)\n// identity can be any value: name, email, some id etc.\nauto identity = \"Alice\";\nauto aliceJwt = jwtGenerator.generateToken(identity);\n\n// as result you get users JWT, it looks like this: \"eyJraWQiOiI3MGI0NDdlMzIxZjNhMGZkIiwidHlwIjoiSldUIiwiYWxnIjoiVkVEUzUxMiIsImN0eSI6InZpcmdpbC1qd3Q7dj0xIn0.eyJleHAiOjE1MTg2OTg5MTcsImlzcyI6InZpcmdpbC1iZTAwZTEwZTRlMWY0YmY1OGY5YjRkYzg1ZDc5Yzc3YSIsInN1YiI6ImlkZW50aXR5LUFsaWNlIiwiaWF0IjoxNTE4NjEyNTE3fQ.MFEwDQYJYIZIAWUDBAIDBQAEQP4Yo3yjmt8WWJ5mqs3Yrqc_VzG6nBtrW2KIjP-kxiIJL_7Wv0pqty7PDbDoGhkX8CJa6UOdyn3rBWRvMK7p7Ak\"\n// you can provide users with JWT at registration or authorization steps\n// Send a JWT to client-side\nauto jwtString = aliceJwt.stringRepresentation();\n```\n\nFor 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:\n\n[Node.js](https://github.com/VirgilSecurity/sample-backend-nodejs) | [Golang](https://github.com/VirgilSecurity/sample-backend-go) | [PHP](https://github.com/VirgilSecurity/sample-backend-php) | [Java](https://github.com/VirgilSecurity/sample-backend-java) | [Python](https://github.com/VirgilSecurity/virgil-sdk-python/tree/master#sample-backend-for-jwt-generation)\n and follow the instructions in README.\n \n### Set up Card Verifier\n\nVirgil Card Verifier helps you automatically verify signatures of a user's Card, for example when you get a Card from Virgil Cards Service.\n\nBy default, `VirgilCardVerifier` verifies only two signatures - those of a Card owner and Virgil Cards Service.\n\nSet up `VirgilCardVerifier` with the following lines of code:\n\n```cpp\n#include \u003cvirgil/sdk/cards/verification/VirgilCardVerifier.h\u003e\n\nusing virgil::sdk::VirgilBase64;\nusing virgil::sdk::cards::verification::VirgilCardVerifier;\nusing virgil::sdk::cards::verification::VerifierCredentials;\nusing virgil::sdk::cards::verification::Whitelist;\nusing virgil::sdk::crypto::Crypto;\n\nauto crypto = std::shared_ptr\u003cCrypto\u003e();\n\nauto publicKeyData = VirgilBase64::decode(publicKeyStr);\nauto yourBackendVerifierCredentials = VerifierCredentials(\"YOUR_BACKEND\", publicKeyData);\n\nauto yourBackendWhitelist = Whitelist({ yourBackendVerifierCredentials });\n\nauto cardVerifier = VirgilCardVerifier(crypto, { yourBackendWhitelist });\n```\n\n### Set up Card Manager\n\nThis subsection shows how to set up a Card Manager module to help you manage users' public keys.\n\nWith Card Manager you can:\n- specify an access Token (JWT) Provider.\n- specify a Card Verifier used to verify signatures of your users, your App Server, Virgil Services (optional).\n\nUse the following lines of code to set up the Card Manager:\n\n```cpp\n#include \u003cvirgil/sdk/cards/CardManager.h\u003e\n\nusing virgil::sdk::cards::CardManager;\n\n// initialize cardManager and specify accessTokenProvider, cardVerifier\nauto cardManager = CardManager(crypto, accessTokenProvider, cardVerifier);\n```\n\n## Usage Examples\n\nBefore you start practicing with the usage examples, make sure that the SDK is configured. See the [Configure SDK](#configure-sdk) section for more information.\n\n### Generate and publish Virgil Cards at Cards Service\n\nUse the following lines of code to create a user's Card with a public key inside and publish it at Virgil Cards Service:\n\n```cpp\n#include \u003cvirgil/sdk/cards/CardManager.h\u003e\n\nusing virgil::sdk::crypto::Crypto;\nusing virgil::sdk::cards::CardManager;\n\n// use Virgil Crypto\nauto crypto = std::make_shared\u003cCrypto\u003e();\n\n// generate a key pair\nauto keyPair = crypto-\u003egenerateKeyPair();\n\n// publish card on Cards Service\nauto future = cardManager.publishCard(keyPair.privateKey(), keyPair.publicKey());\nauto card = future.get();\n```\n\n### Sign then encrypt data\n\nVirgil Core SDK allows you to use a user's private key and their Virgil Cards to sign and encrypt any kind of data.\n\nIn 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.\n\n```cpp\n#include \u003cvirgil/sdk/cards/CardManager.h\u003e\n\nusing virgil::sdk::cards::CardManager;\nusing virgil::sdk::crypto::keys::PublicKey;\nusing virgil::sdk::VirgilByteArrayUtils;\n\n// prepare a message\nauto messageToEncrypt = \"Hello, Bob!\";\nauto dataToEncrypt = VirgilByteArrayUtils::stringToBytes(messageToEncrypt);\n\n// using cardManager search for Bob's cards on Cards Service\nauto future = cardManager.searchCards(\"Bob\");\nauto bobCards = future.get();\n\nauto bobRelevantCardsPublicKeys = std::vector\u003cPublicKey\u003e();\n\nfor (auto\u0026 card : bobCards)\n  bobRelevantCardsPublicKeys.push_back(card.publicKey());\n\n// sign a message with a private key then encrypt using Bob's public keys\nauto encryptedData = crypto-\u003esignThenEncrypt(dataToEncrypt, alicePrivateKey, bobRelevantCardsPublicKeys);\n```\n\n### Decrypt data and verify signature\n\nOnce 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:\n\n```cpp\n#include \u003cvirgil/sdk/cards/CardManager.h\u003e\n\nusing virgil::sdk::cards::CardManager;\nusing virgil::sdk::crypto::keys::PublicKey;\n\n// using cardManager search for Alice's cards on Cards Service\nauto future = cardManager.searchCards(\"Alice\");\nauto aliceCards = future.get();\n\nauto aliceRelevantCardsPublicKeys = std::vector\u003cPublicKey\u003e();\n\nfor (auto\u0026 card : aliceCards)\n  aliceRelevantCardsPublicKeys.push_back(card.publicKey());\n\n// decrypt with a private key and verify using one of Alice's public keys\nauto decryptedData = crypto-\u003edecryptThenVerify(encryptedData, bobPrivateKey, aliceRelevantCardsPublicKeys);\n```\n\n### Get Card by its ID\n\nUse the following lines of code to get a user's card from Virgil Cloud by its ID:\n\n```cpp\n#include \u003cvirgil/sdk/cards/CardManager.h\u003e\n\nusing virgil::sdk::cards::CardManager;\n\n// using cardManager get a user's card from the Cards Service\nauto getFuture = cardManager.getCard(\"f4bf9f7fcbedaba0392f108c59d8f4a38b3838efb64877380171b54475c2ade8\");\nauto card = getFuture.get()\n```\n\n### Get Card by user's identity\n\nFor a single user, use the following lines of code to get a user's Card by a user's `identity`:\n\n```cpp\n#include \u003cvirgil/sdk/cards/CardManager.h\u003e\n\nusing virgil::sdk::cards::CardManager;\n\n// using cardManager search for user's cards on Cards Service\nauto searchFuture = cardManager.searchCards(\"Bob\");\nauto cards = searchFuture.get();\n```\n\n## Docs\n\nVirgil Security has a powerful set of APIs, and the [Developer Documentation](https://developer.virgilsecurity.com/) can get you started today.\n\n## License\n\nThis library is released under the [3-clause BSD License](LICENSE).\n\n## Support\n\nOur developer support team is here to help you. Find out more information on our [Help Center](https://help.virgilsecurity.com/).\n\nYou can find us on [Twitter](https://twitter.com/VirgilSecurity) or send us email support@VirgilSecurity.com.\n\nAlso, get extra help from our support team on [Slack](https://virgilsecurity.com/join-community).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fvirgil-sdk-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgilsecurity%2Fvirgil-sdk-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fvirgil-sdk-cpp/lists"}