{"id":15069104,"url":"https://github.com/comodal/secret-shamiracle","last_synced_at":"2025-04-10T17:44:11.157Z","repository":{"id":194797080,"uuid":"148412738","full_name":"comodal/secret-shamiracle","owner":"comodal","description":"Simple builder and utility functions for creating Shamir secret shares and secret reconstruction.","archived":false,"fork":false,"pushed_at":"2019-06-12T16:42:29.000Z","size":176,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T15:22:01.725Z","etag":null,"topics":["java-11","shamir","shamir-secret-sharing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/comodal.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}},"created_at":"2018-09-12T02:59:11.000Z","updated_at":"2024-12-18T15:59:05.000Z","dependencies_parsed_at":"2023-09-15T05:55:18.714Z","dependency_job_id":"4c978504-ddf1-460b-8fab-ce429f74521f","html_url":"https://github.com/comodal/secret-shamiracle","commit_stats":null,"previous_names":["comodal/secret-shamiracle"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comodal%2Fsecret-shamiracle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comodal%2Fsecret-shamiracle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comodal%2Fsecret-shamiracle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comodal%2Fsecret-shamiracle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/comodal","download_url":"https://codeload.github.com/comodal/secret-shamiracle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262298,"owners_count":21074283,"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":["java-11","shamir","shamir-secret-sharing"],"created_at":"2024-09-25T01:40:29.955Z","updated_at":"2025-04-10T17:44:11.127Z","avatar_url":"https://github.com/comodal.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# secret-shamiracle [![Build Status](https://travis-ci.org/comodal/secret-shamiracle.svg?branch=master)](https://travis-ci.org/comodal/secret-shamiracle)  [![Download](https://api.bintray.com/packages/comodal/libraries/shamir/images/download.svg)](https://bintray.com/comodal/libraries/shamir/_latestVersion) [![codecov](https://codecov.io/gh/comodal/secret-shamiracle/branch/master/graph/badge.svg)](https://codecov.io/gh/comodal/secret-shamiracle) [![License](http://img.shields.io/badge/license-Apache--2-blue.svg?style=flat)](LICENSE)\n\n\u003e Simple builder and utility functions for creating Shamir secret shares and secret reconstruction.\n\n### Credits\n* [Shamir secret sharing wiki](https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing#Shamir's_secret-sharing_scheme)\n* Credit to Stackoverflow user [JerzySkalski](https://stackoverflow.com/users/4513021/jerzyskalski) for providing a [working example](https://stackoverflow.com/a/34365904/3754157) which limits the finite field with prime modulus division.\n\n### Components\n* [Shamir.java](./systems.comodal.shamir/src/main/java/systems/comodal/shamir/Shamir.java#L1): Minimal static methods to facilitate the creation of shares and the reconstruction of a secret.\n* [ShamirSharesBuilder.java](./systems.comodal.shamir/src/main/java/systems/comodal/shamir/ShamirSharesBuilder.java#L1): A mutable builder to help coordinate the state needed to create and validate shares.\n\n### Shares Builder Usage\n\n* Required Shares: The minimum number of shares needed to reconstruct the free coefficient secret.\n* Total Shares: The total number of shares to generate.\n* Prime:\n  * Must be supplied directly, or indirectly as a [Mersenne Prime](https://en.wikipedia.org/wiki/Mersenne_prime#List_of_known_Mersenne_primes) exponent.\n  * Must be larger than all secrets used.\n* Random: Defaults to `new SecureRandom()`\n* Secret:\n  * May be provided as a byte[] or a BigInteger to `initSecrets(secret)`.\n  * Defaults to a random value in the range (0, prime) with a call to `initSecrets()`.\n\n```java\nvar sharesBuilder = Shamir.buildShares()\n  .numRequiredShares(3)\n  .numShares(5)\n  .mersennePrimeExponent(521)\n  .initSecrets(\"Shamir's Secret\".getBytes(UTF_8));\n\nBigInteger[] shares = sharesBuilder.createShares();\n\n// Validate secret reconstruction for all share combinations of size 'numRequiredShares'.\n// Throws an IllegalStateException if any reconstructed secret does not equal the original.\nsharesBuilder.validateShareCombinations(shares);\n\n// Reconstruct secret.\nvar coordinates = Map.of(BigInteger.valueOf(1), shares[0],\n                         BigInteger.valueOf(3), shares[2],\n                         BigInteger.valueOf(5), shares[4]);\nvar secret = Shamir.reconstructSecret(coordinates, sharesBuilder.getPrime());\nvar secretString = new String(secret.toByteArray(), UTF_8);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomodal%2Fsecret-shamiracle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomodal%2Fsecret-shamiracle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomodal%2Fsecret-shamiracle/lists"}