{"id":16480604,"url":"https://github.com/virgilsecurity/virgil-sdk-java-android","last_synced_at":"2025-08-08T02:39:08.806Z","repository":{"id":57729450,"uuid":"52774196","full_name":"VirgilSecurity/virgil-sdk-java-android","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-06-24T10:32:03.000Z","size":136867,"stargazers_count":26,"open_issues_count":2,"forks_count":5,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-17T22:24:16.048Z","etag":null,"topics":["android","cryptography","encryption","end-to-end-encryption","gdpr","hipaa","java","maven","pki","sdk"],"latest_commit_sha":null,"homepage":"https://virgilsecurity.com/","language":"Java","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":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-29T08:00:51.000Z","updated_at":"2024-10-25T09:05:45.000Z","dependencies_parsed_at":"2022-09-10T23:41:07.245Z","dependency_job_id":null,"html_url":"https://github.com/VirgilSecurity/virgil-sdk-java-android","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-java-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-java-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-java-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-sdk-java-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VirgilSecurity","download_url":"https://codeload.github.com/VirgilSecurity/virgil-sdk-java-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757124,"owners_count":20505337,"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":["android","cryptography","encryption","end-to-end-encryption","gdpr","hipaa","java","maven","pki","sdk"],"created_at":"2024-10-11T13:04:45.469Z","updated_at":"2025-03-21T07:30:32.072Z","avatar_url":"https://github.com/VirgilSecurity.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Virgil Core SDK \u0026 Crypto Stack Java/Android\n\n[![Build Status](https://api.travis-ci.org/VirgilSecurity/virgil-sdk-java-android.svg?branch=master)](https://travis-ci.org/VirgilSecurity/virgil-sdk-java-android)\n[![Maven](https://img.shields.io/maven-central/v/com.virgilsecurity.sdk/sdk.svg)](https://search.maven.org/artifact/com.virgilsecurity.sdk/sdk)\n[![GitHub license](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://github.com/VirgilSecurity/virgil/blob/master/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-java)\n\n## Installation\n\nThe Virgil Core SDK is provided as set of packages named *com.virgilsecurity.sdk*. Packages are distributed via Maven repository. In this guide you'll also find one more package - Virgil Crypto Library, that is used by the SDK to perform cryptographic operations.\n\n### Target\n\n* Java 7+.\n* Android API 16+.\n\n### Prerequisites\n\n* Java Development Kit (JDK) 7+\n* Maven 3+\n\n### Installing the package\n\nYou can easily add SDK dependency to your project, just follow the examples below:\n\n#### Maven\n\nUse this packages for Java projects:\n\n```\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.virgilsecurity.sdk\u003c/groupId\u003e\n        \u003cartifactId\u003esdk\u003c/artifactId\u003e\n        \u003cversion\u003e\u003clatest-version\u003e\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n#### Gradle\n\nAdd jcenter() repository if missing:\n\n```\nrepositories {\n    jcenter()\n}\n```\n\nUse this packages for Android projects:\n\n```\n    implementation \"com.virgilsecurity.sdk:sdk-android:\u003clatest-version\u003e\"\n```\n\nThe **\\\u003clatest-version\u003e** of the SDK can be found in the [Maven Central Repository](https://mvnrepository.com/artifact/com.virgilsecurity.sdk/sdk) or in the header of current readme.\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```java\n// Get generated token from server-side\nfinal String authenticatedQueryToServerSide =\n        \"eyJraWQiOiI3MGI0NDdlMzIxZjNhMGZkIiwidHlwIjoiSldUIiwiYWxnIjoiVkVEUzUxMiIsImN0eSI6InZpcmdpbC1qd3Q7dj0xIn0.eyJleHAiOjE1MTg2OTg5MTcsImlzcyI6InZpcmdpbC1iZTAwZTEwZTRlMWY0YmY1OGY5YjRkYzg1ZDc5Yzc3YSIsInN1YiI6ImlkZW50aXR5LUFsaWNlIiwiaWF0IjoxNTE4NjEyNTE3fQ.MFEwDQYJYIZIAWUDBAIDBQAEQP4Yo3yjmt8WWJ5mqs3Yrqc_VzG6nBtrW2KIjP-kxiIJL_7Wv0pqty7PDbDoGhkX8CJa6UOdyn3rBWRvMK7p7Ak\";\n\n// Setup AccessTokenProvider\nCallbackJwtProvider.GetTokenCallback getTokenCallback = new CallbackJwtProvider.GetTokenCallback() {\n\n        @Override\n        public String onGetToken(TokenContext tokenContext) {\n                return authenticatedQueryToServerSide;\n        }\n};\n// initialize JWT provider\nAccessTokenProvider accessTokenProvider =\n        new CallbackJwtProvider(getTokenCallback);\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```java\n// App Key (you got this Key at Virgil Dashboard)\nString appKeyBase64 = \"MC4CAQAwBQYDK2VwBCIEINlK4BhgsijAbNmUqU6us0ZU9MGi+HxdYCA6TdZeHjR4\";\nbyte[] appKeyData = ConvertionUtils.base64ToBytes(appKeyBase64);\n\n// Crypto library imports a private key into a necessary format\nVirgilCrypto crypto = new VirgilCrypto();\nPrivateKey appKey = crypto.importPrivateKey(appKeyData);\n\n// initialize accessTokenSigner that signs users JWTs\nAccessTokenSigner accessTokenSigner = new VirgilAccessTokenSigner();\n\n// use your App Credentials you got at Virgil Dashboard:\nString appId = \"be00e10e4e1f4bf58f9b4dc85d79c77a\"; // App ID\nString appKeyId = \"70b447e321f3a0fd\"; // App Key ID\nTimeSpan ttl = TimeSpan.fromTime(1, TimeUnit.HOURS); // 1 hour (JWT's lifetime)\n\n// setup JWT generator with necessary parameters:\nJwtGenerator jwtGenerator = new JwtGenerator(appId, appKey, appKeyId, ttl, accessTokenSigner);\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.\nString identity = \"Alice\";\nJwt 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\nString 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```java\n// initialize Crypto library\nCardCrypto cardCrypto = new VirgilCardCrypto();\n\nVerifierCredentials yourBackendVerifierCredentials =\n        new VerifierCredentials(\"YOUR_BACKEND\",\n                ConvertionUtils.base64ToBytes(PUBLIC_KEY_STR));\n\nWhitelist yourBackendWhiteList =\n        new Whitelist(Arrays.asList(yourBackendVerifierCredentials));\n\nCardVerifier cardVerifier = new VirgilCardVerifier(cardCrypto,\n        Arrays.asList(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```java\n// initialize cardManager and specify accessTokenProvider, cardVerifier\nCardManager cardManager = new CardManager(cardCrypto, 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```java\nimport com.virgilsecurity.crypto.VirgilCrypto;\n\nVirgilCrypto crypto = new VirgilCrypto();\n\n// generate a key pair\nVirgilKeyPair keyPair = crypto.generateKeyPair();\n\n// save a private key into key storage\nprivateKeyStorage.store(keyPair.getPrivateKey(), \"Alice\", null);\n\n// publish user's card on the Cards Service\ntry {\n    Card card = cardManager.publishCard(keyPair.getPrivateKey(), keyPair.getPublicKey(), \"Alice\");\n    // Card is created\n} catch (Exception e) {\n    // Error occured\n}\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```java\nimport com.virgilsecurity.crypto.VirgilCrypto;\n\nVirgilCrypto crypto = new VirgilCrypto();\n\n// prepare a message\nString messageToEncrypt = \"Hello, Bob!\";\nbyte[] dataToEncrypt = ConvertionUtils.toBytes(messageToEncrypt);\n\n// prepare a user's private key\nTuple\u003cPrivateKey, Map\u003cString, String\u003e\u003e alicePrivateKeyEntry =\n        privateKeyStorage.load(\"Alice\");\nVirgilPrivateKey alicePrivateKey =\n        (VirgilPrivateKey) alicePrivateKeyEntry.getLeft();\n\n// using cardManager search for user's cards on Cards Service\ntry {\n    List\u003cCard\u003e cards = cardManager.searchCards(\"Bob\");\n    // Cards are obtained\n    List\u003cVirgilPublicKey\u003e bobRelevantCardsPublicKeys = new ArrayList\u003c\u003e();\n    for (Card card : cards) {\n        if (!card.isOutdated()) {\n            bobRelevantCardsPublicKeys.add(\n                    (VirgilPublicKey) card.getPublicKey());\n        }\n    }\n    // sign a message with a private key then encrypt on a public key\n    byte[] encryptedData = crypto.signThenEncrypt(dataToEncrypt,\n            alicePrivateKey, bobRelevantCardsPublicKeys);\n} catch (CryptoException | VirgilServiceException e) {\n    // Error occured\n}\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```java\nimport com.virgilsecurity.crypto.VirgilCrypto;\n\nVirgilCrypto crypto = new VirgilCrypto();\n\n// prepare a user's private key\nTuple\u003cPrivateKey, Map\u003cString, String\u003e\u003e bobPrivateKeyEntry =\n        privateKeyStorage.load(\"Bob\");\nVirgilPrivateKey bobPrivateKey =\n        (VirgilPrivateKey) bobPrivateKeyEntry.getLeft();\n\ntry {\n    // using cardManager search for user's cards on Cards Service\n    List\u003cCard\u003e cards = cardManager.searchCards(\"Alice\");\n    // Cards are obtained\n    List\u003cVirgilPublicKey\u003e aliceRelevantCardsPublicKeys = new ArrayList\u003c\u003e();\n    for (Card card : cards) {\n        if (!card.isOutdated()) {\n            aliceRelevantCardsPublicKeys.add(\n                    (VirgilPublicKey) card.getPublicKey());\n        }\n    }\n\n    // decrypt with a private key and verify using a public key\n    byte[] decryptedData = crypto.decryptThenVerify(encryptedData,\n            bobPrivateKey, aliceRelevantCardsPublicKeys);\n} catch (CryptoException | VirgilServiceException e) {\n    // Error occured\n}\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```java\n// using cardManager get a user's card from the Cards Service\ntry {\n    Card card = cardManager.getCard(\"f4bf9f7fcbedaba0392f108c59d8f4a38b3838efb64877380171b54475c2ade8\");\n    // Card is obtained\n} catch (CryptoException | VirgilServiceException e) {\n    // Error occured\n}\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```java\ntry {\n    List\u003cCard\u003e cards = cardManager.searchCards(\"Bob\");\n    // Cards are obtained\n} catch (CryptoException | VirgilServiceException e) {\n    // Error occured\n}\n```\n\n## Run benchmarks\n\nBuild artifacts with a command\n```bash\nmvn clean install -DskipTests\n```\n\nA JAR file with benchmarks and all dependencies will be build. You can find it at `/benchmark/target/benchmark.jar`.\nYou can copy this JAR file to any other machine with install JRE and run with a command\n```bash\njava -jar \u003cpath_to_jar\u003e\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\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fvirgil-sdk-java-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgilsecurity%2Fvirgil-sdk-java-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fvirgil-sdk-java-android/lists"}