{"id":19198489,"url":"https://github.com/virgilsecurity/virgil-pythia-java","last_synced_at":"2026-02-13T03:21:25.833Z","repository":{"id":146283189,"uuid":"129749930","full_name":"VirgilSecurity/virgil-pythia-java","owner":"VirgilSecurity","description":"Virgil Pythia SDK allows developers to implement Pythia protocol to create breach-proof passwords, immune to offline and online attacks.","archived":false,"fork":false,"pushed_at":"2020-05-21T21:31:04.000Z","size":391,"stargazers_count":0,"open_issues_count":1,"forks_count":3,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-23T05:13:52.978Z","etag":null,"topics":["breach-proof-password","cryptography","encryption","java","pythia","pythia-sdk","sdk","virgil-pythia"],"latest_commit_sha":null,"homepage":"https://developer.virgilsecurity.com/docs/java/use-cases/v5/breach-proof-password","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VirgilSecurity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-16T13:43:34.000Z","updated_at":"2020-05-08T19:41:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"7f42601a-a763-448e-949e-48cf090ba88e","html_url":"https://github.com/VirgilSecurity/virgil-pythia-java","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/VirgilSecurity/virgil-pythia-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-pythia-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-pythia-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-pythia-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-pythia-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VirgilSecurity","download_url":"https://codeload.github.com/VirgilSecurity/virgil-pythia-java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VirgilSecurity%2Fvirgil-pythia-java/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259977564,"owners_count":22941114,"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":["breach-proof-password","cryptography","encryption","java","pythia","pythia-sdk","sdk","virgil-pythia"],"created_at":"2024-11-09T12:22:24.229Z","updated_at":"2026-02-13T03:21:25.827Z","avatar_url":"https://github.com/VirgilSecurity.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Virgil Pythia Java SDK\n[![Build](https://github.com/VirgilSecurity/pythia-java/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/VirgilSecurity/pythia-java/actions/workflows/build-and-test.yml)\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) | [Install and configure SDK](#install-and-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 an SDK which allows you to communicate with Virgil Pythia Service and implement Pythia protocol for the following use cases: \n- **Breach-proof password**. Pythia is a technology that gives you a new, more secure mechanism that \"breach-proofs\" user passwords and lessens the security risks associated with weak passwords by providing cryptographic leverage for the defender (by eliminating offline password cracking attacks), detection for online attacks, and key rotation to recover from stolen password databases.\n- **BrainKey**. User's Private Key which is based on user's password. BrainKey can be easily restored and is resistant to online and offline attacks.\n\nIn both cases you get the mechanism which assures you that neither Virgil nor attackers know anything about user's password.\n\n## SDK Features\n- communicate with Virgil Pythia Service\n- manage your Pythia application credentials\n- create, verify and update user's breach-proof password\n- generate user's BrainKey\n- use [Virgil Crypto Pythia library][_virgil_crypto_pythia]\n\n## Install and configure SDK\n\nThe Virgil Java SDK is provided as a package named com.virgilsecurity.sdk. The package is distributed via Maven repository.\n\nThe package is available for:\n- Java 8 and newer\n- Android API 21 and newer\n\nBuild prerequisites (for contributors):\n- Java Development Kit (JDK) 17+\n- Gradle (via `./gradlew`)\n\nYou can easily add SDK dependency to your project, just follow the examples below.\n\n### Install SDK Package\n\n#### Maven\n\n[Apache Maven](https://maven.apache.org/) is a software project management and comprehension tool.\n\nTo integrate Virgil SDK into your Java project using Maven, set up dependencies in your `pom.xml`:\n\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.virgilsecurity\u003c/groupId\u003e\n        \u003cartifactId\u003epythia\u003c/artifactId\u003e\n        \u003cversion\u003e0.3.7\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n#### Gradle\n\n[Gradle](https://gradle.org/) is an open-source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration.\n\n##### Server\n\nTo integrate Virgil SDK into your Java project using Gradle, set up dependencies in your `build.gradle`:\n\n```\ndependencies {\n    implementation 'com.virgilsecurity:pythia:0.3.7'\n}\n```\n\n##### Android\n\nSet up dependencies in your `build.gradle`:\n\n```\nrepositories {\n    google()\n    mavenCentral()\n}\n\ndependencies {\n    implementation 'com.virgilsecurity:pythia-android:0.3.7'\n}\n```\n\n### Configure SDK\n\nWhen you create a Pythia Application on the [Virgil Dashboard](https://dashboard.virgilsecurity.com/) you will receive Application credentials including: Proof Key and App ID. Specify your Pythia Application and Virgil account credentials in a Pythia SDK class instance.\nThese credentials are used for the following purposes:\n- generating a JWT token that is used for authorization on the Virgil Services\n- creating a user's breach-proof password\n\nHere is an example of how to specify your credentials SDK class instance:\n```java\n// here set your Virgil Account and Pythia Application credentials\nPythiaContext context = new PythiaContext.Builder()\n    .setAppId(\"APP_ID\")\n    .setApiPublicKeyIdentifier(\"API_KEY_ID\")\n    .setApiKey(\"API_KEY\")\n    .setProofKeys(Arrays.asList(\"PK.1.PROOF_KEY\"))\n    .setPythiaCrypto(new VirgilPythiaCrypto())\n    .build();\n\nPythia pythia = new Pythia(context);\n```\n\n\n## Usage Examples\n\n### Breach-proof password\n\nVirgil Pythia SDK lets you easily perform all the necessary operations to create, verify and update user's breach-proof password without requiring any additional actions and use Virgil Crypto library.\n\nFirst of all, you need to set up your database to store users' breach-proof passwords. Create additional columns in your database for storing the following parameters:\n\u003ctable class=\"params\"\u003e\n\u003cthead\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003cth\u003eParameters\u003c/th\u003e\n\t\t\t\u003cth\u003eType\u003c/th\u003e\n\t\t\t\u003cth\u003eSize (bytes)\u003c/th\u003e\n\t\t\t\u003cth\u003eDescription\u003c/th\u003e\n\t\t\u003c/tr\u003e\n\u003c/thead\u003e\n\n\u003ctbody\u003e\n\u003ctr\u003e\n\t\u003ctd\u003esalt\u003c/td\u003e\n\t\u003ctd\u003eblob\u003c/td\u003e\n\t\u003ctd\u003e32\u003c/td\u003e\n\t\u003ctd\u003e Unique random string that is generated by Pythia SDK for each user\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\t\u003ctd\u003edeblindedPassword\u003c/td\u003e\n\t\u003ctd\u003eblob \u003c/td\u003e\n\t\u003ctd\u003e384 \u003c/td\u003e\n\t\u003ctd\u003euser's breach-proof password\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n\t\u003ctd\u003eversion\u003c/td\u003e\n\t\u003ctd\u003eint \u003c/td\u003e\n\t\u003ctd\u003e4 \u003c/td\u003e\n\t\u003ctd\u003eVersion of your Pythia Application credentials. This parameter has the same value for all users unless you generate new Pythia credentials on Virgil Dashboard\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/tbody\u003e\n\u003c/table\u003e\n\nNow we can start creating breach-proof passwords for users. Depending on the situation, you will use one of the following Pythia SDK functions:\n- `createBreachProofPassword` is used to create a user's breach-proof password on your Application Server.\n- `verifyBreachProofPassword` is used to verify a user's breach-proof password.\n\n#### Create Breach-Proof Password\n\nUse this flow to create a new breach-proof password for a user.\n\n\u003e Remember, if you already have a database with user passwords, you don't have to wait until a user logs in into your system to implement Pythia. You can go through your database and create breach-proof user passwords at any time.\n\nSo, in order to create a user's breach-proof password for a new database or available one, go through the following operations:\n- Take a user's password (or its hash or whatever you use) and pass it into a `CreateBreachProofPassword` function in SDK on your Server side.\n- Pythia SDK generates unique user's **salt** and **version** (which is the same for every user until you change your app credentials on Pythia Service). You need to store user's salt and version in your database in associated columns created on previous step.\n- Pythia SDK blinds a password and sends a request to Pythia Service to get a **transformed blinded password**.\n- Pythia SDK de-blinds the transformed blinded password into a user's **deblinded password** (that we call **breach-proof password**).\n\n```java\n// create a new Breach-proof password using user's password or its hash\nBreachProofPassword pwd = pythia.createBreachProofPassword(\"USER_PASSWORD\");\n\n// save Breach-proof password parameters into your users DB\n```\n\nAfter performing `createBreachProofPassword` function you get previously mentioned parameters (`salt`, `deblindedPassword`, `version`), save these parameters into corresponding columns in your database.\n\nCheck that you updated all database records and delete the now unnecessary column where user passwords were previously stored.\n\n#### Verify Breach-Proof Password\n\nUse this flow when a user already has his or her own breach-proof password in your database. You will have to pass his or her password into an `verifyBreachProofPassword` function:\n\n```java\n// get user's Breach-proof password parameters from your users DB\n\n// ...\n\n// calculate user's Breach-proof password parameters\n// compare these parameters with parameters from your DB\nboolean isValid = pythia.verifyBreachProofPassword(\"USER_PASSWORD\", pwd, true);\n\nif (!isValid) {\n    throw new Exception(\"Authentication failed\");\n}\n```\n\nThe difference between the `verifyBreachProofPassword` and `createBreachProofPassword` functions is that the verification of Pythia Service is optional in `verifyBreachProofPassword` function, which allows you to achieve maximum performance when processing data. You can turn on a proof step in `verifyBreachProofPassword` function if you have any suspicions that a user or Pythia Service were compromised.\n\n#### Update breach-proof passwords\n\nThis step will allow you to use an `updateToken` in order to update users' breach-proof passwords in your database.\n\n\u003e Use this flow only if your database was COMPROMISED.\n\nHow it works:\n- Access your [Virgil Dashboard][_dashboard] and press the \"My Database Was Compromised\" button.\n- Pythia Service generates a special updateToken and new Proof Key.\n- You then specify new Pythia Application credentials in the Pythia SDK on your Server side.\n- Then you use `UpdateBreachProofPassword` function to create new breach-proof passwords for your users (you don't need to regenerate user's password).\n- Finally, you save the new breach-proof passwords into your database.\n\nHere is an example of using the `updateBreachProofPassword` function:\n```java\n// get previous user's verifyBreachProofPassword parameters from a compromised DB\n\n// ...\n\n// set up an updateToken that you got on the Virgil Dashboard\n// update previous user's Breach-proof password, and save new one into\n// your DB\n\nBreachProofPassword updatedPwd =\n    pythia.updateBreachProofPassword(\"UT.1.2.UPDATE_TOKEN\", pwd);\n```\n### BrainKey\n\n*PYTHIA* Service can be used directly as a means to generate strong cryptographic keys based on user's **password** or other secret data. We call these keys the **BrainKeys**. Thus, when you need to restore a Private Key you use only user's Password and Pythia Service.\n\nIn order to create a user's BrainKey, go through the following operations:\n- Register your E2EE application on [Virgil Dashboard][_dashboard] and get your app credentials\n- Generate your API key or use available\n- Set up **JWT provider** using previously mentioned parameters (**App ID, API key, API key ID**) on the Server side\n- Generate JWT token with **user's identity** inside and transmit it to Client side (user's side)\n- On Client side set up **access token provider** in order to specify JWT provider\n- Setup BrainKey function with access token provider and pass user's password\n- Send BrainKey request to Pythia Service\n- Generate a strong cryptographic keypair based on a user's password or other user's secret\n\n\n#### Generate BrainKey based on user's password\n```java\n// 1. Specify your JWT provider\n\n// Get generated token from server-side\nfinal String authenticatedQueryToServerSide = \"eyJraWQiOiI3MGI0NDdlMzIxZjNhMGZkIiwidHlwIjoiSldUIiwiYWxnIjoiVkVEUzUxMiIsImN0eSI6InZpcmdpbC1qd3Q7dj0xIn0.eyJleHAiOjE1MTg2OTg5MTcsImlzcyI6InZpcmdpbC1iZTAwZTEwZTRlMWY0YmY1OGY5YjRkYzg1ZDc5Yzc3YSIsInN1YiI6ImlkZW50aXR5LUFsaWNlIiwiaWF0IjoxNTE4NjEyNTE3fQ.MFEwDQYJYIZIAWUDBAIDBQAEQP4Yo3yjmt8WWJ5mqs3Yrqc_VzG6nBtrW2KIjP-kxiIJL_7Wv0pqty7PDbDoGhkX8CJa6UOdyn3rBWRvMK7p7Ak\";\n\n// Setup AccessTokenProvider\nAccessTokenProvider accessTokenProvider = new CachingJwtProvider(new RenewJwtCallback() {\n\n    @Override\n    public Jwt renewJwt(TokenContext tokenContext) {\n        return new Jwt(authenticatedQueryToServerSide);\n    }\n});\n\n// 2. Setup BrainKey\n\nBrainKeyContext brainKeyContext = new BrainKeyContext.Builder()\n        .setAccessTokenProvider(accessTokenProvider)\n        .setPythiaCrypto(new VirgilPythiaCrypto())\n        .setPythiaClient(new VirgilPythiaClient())\n        .build();\nBrainKey brainKey = new BrainKey(brainKeyContext);\n\n// Generate default public/private keypair which is Curve ED25519\n// If you need to generate several BrainKeys for the same password,\n// use different IDs (optional). Default brainKeyId value is null.\nVirgilKeyPair keyPair = brainKey.generateKeyPair(\"Your password\", \"Optional BrainKey id\");\n```\n\n#### Generate BrainKey based on unique URL\nThe typical BrainKey implementation uses a password or concatenated answers to security questions to regenerate the user’s private key. But a unique session link generated by the system admin can also do the trick.\n\nThis typically makes the most sense for situations where it’s burdensome to require a password each time a user wants to send or receive messages, like single-session chats in a browser application.\n\nHere’s the general flow of how BrainKey can be used to regenerate a private key based on a unique URL:\n- When the user is ready to begin an encrypted messaging session, the application sends the user an SMS message\n- The SMS message contains a unique link like https://healthcare.app/?session=abcdef13803488\n- The string 'abcdef13803488' is used as a password for the private key regeneration\n- By clicking on the link, the user immediately establishes a secure session using their existing private key regenerated with Brainkey and does not need to input an additional password\n\nImportant notes for implementation:\n- The link is one-time use only. When the user clicks on the link, the original link expires and cannot be used again, and so a new link has to be created for each new chat session.\n- All URL links must be short-lived (recommended lifetime is 1 minute).\n- The SMS messages should be sent over a different channel than the one the user will be using for the secure chat session.\n- If you’d like to add additional protection to ensure that the person clicking the link is the intended chat participant, users can be required to submit their name or any other security question. This answer will need to be built in as part of the BrainKey password.\n\n```go\n...\n    VirgilKeyPair keyPair = brainKey.generateKeyPair(\"abcdef13803488\", \"Optional User SSN\");\n...\n```\n\u003e Note! if you don't need to use additional parameters, like \"Optional User SSN\", you can just omit it: `VirgilKeyPair keyPair = brainKey.generateKeyPair(\"abcdef13803488\");`\n\n\n## Docs\nVirgil Security has a powerful set of APIs, and the documentation below can get you started today.\n\n* [Breach-Proof Password][_pythia_use_case] Use Case\n* [Brain Key][_brain_key_use_case] Use Case\n* [The Pythia PRF Service](https://eprint.iacr.org/2015/644.pdf) - foundation principles of the protocol\n* [Virgil Security Documentation][_documentation]\n\n## License\n\nThis library is released under the [3-clause BSD License](LICENSE).\n\n## Support\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[_virgil_crypto_pythia]: https://github.com/VirgilSecurity/pythia\n[_brain_key_use_case]: https://developer.virgilsecurity.com/docs/use-cases/v1/brainkey\n[_pythia_use_case]: https://developer.virgilsecurity.com/docs/java/use-cases/v1/breach-proof-password\n[_documentation]: https://developer.virgilsecurity.com/\n[_dashboard]: https://dashboard.virgilsecurity.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fvirgil-pythia-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgilsecurity%2Fvirgil-pythia-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgilsecurity%2Fvirgil-pythia-java/lists"}