{"id":15409368,"url":"https://github.com/patriksvensson/license-key","last_synced_at":"2025-04-15T16:41:41.661Z","repository":{"id":61995556,"uuid":"279411211","full_name":"patriksvensson/license-key","owner":"patriksvensson","description":" A library for generating and verifying license keys.","archived":false,"fork":false,"pushed_at":"2020-07-13T21:37:24.000Z","size":8,"stargazers_count":63,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T22:35:01.100Z","etag":null,"topics":["license","license-checker","license-checking","software-license","software-licensing"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/license-key","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patriksvensson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-13T21:02:48.000Z","updated_at":"2025-02-08T10:42:37.000Z","dependencies_parsed_at":"2022-10-24T23:00:34.690Z","dependency_job_id":null,"html_url":"https://github.com/patriksvensson/license-key","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patriksvensson%2Flicense-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patriksvensson%2Flicense-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patriksvensson%2Flicense-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patriksvensson%2Flicense-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patriksvensson","download_url":"https://codeload.github.com/patriksvensson/license-key/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249110317,"owners_count":21214307,"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":["license","license-checker","license-checking","software-license","software-licensing"],"created_at":"2024-10-01T16:39:26.166Z","updated_at":"2025-04-15T16:41:41.640Z","avatar_url":"https://github.com/patriksvensson.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# license-key\n\nA library for generating and verifying license keys without requiring\nan Internet connection. For further protection, you can of course\nvalidate the license key over the Internet.\n\n# Features\n\n* Does not require an Internet connection.\n* Easy to revoke specific license keys in a software update.\n* Not possible to disassemble an application to gain\n  insight into how to generate a 100% working key since \n  the verification process doesn't check the whole license key.\n\nFor more information, read \n[Implementing a Partial Serial Number Verification System in Delphi](https://www.brandonstaggs.com/2007/07/26/implementing-a-partial-serial-number-verification-system-in-delphi)\nwhich this crate was based upon.\n\n# Anatomy of a license key\n\nEvery license key consists of a seed, a payload and a checksum.\nEach byte in the payload is an operation of the seed and an\ninitialization vector. The 16-bit checksum is there to quickly check if\nthe key is valid at all, while the seed is a 64-bit hash of something\nthat identifies the license key owner such as an e-mail address or similar.  \n\nThe size of the payload depends on how big the initialization vector is.\nIn the example below, we are using a 5-byte intitialization vector which\nresults in a 5-byte payload.\n\n```text\n┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐\n│0x0│0x1│0x2│0x3│0x4│0x5│0x6│0x7│0x8│0x9│0xa│0xb│0xc│0xd│0xe│0xf│\n├───┴───┴───┴───┴───┴───┴───┴───┴───┼───┴───┴───┴───┴───┼───┴───┤\n│ SEED                              │ PAYLOAD           │ CHECK │\n│                                   │                   │  SUM  │\n└───────────────────────────────────┴───────────────────┴───────┘\n```\n\n# Generating a license key\n\n```rust\nuse license_key::*;\n\n// Define a hasher that will hash the seed and a initialization vector.\n// DON'T USE THIS ONE. It's only for demonstrational purposes.\nstruct DummyHasher { }\nimpl KeyHasher for DummyHasher {\n    fn hash(\u0026self, seed: u64, a: u64, b: u64, c: u64) -\u003e u8 {\n        ((seed ^ a ^ b ^ c) \u0026 0xFF) as u8\n    }\n}\n\n// Create a license generator\n// We use only four triplets in our initialization vector,\n// but in a real world scenario you would want to use a lot more.\nlet generator = Generator::new(\n    DummyHasher { },\n    vec![\n        // DON'T USE THIS ONE.\n        // Generate your own.\n        (114, 83, 170),\n        (60, 208, 27),\n        (69, 14, 202),\n        (61, 232, 54)\n     ],\n);\n\n// Generate a license key using a seed.\n// A seed is unique per license key, and could be a hash of an e-mail address or similar.\n// You can later block individual seeds during verification.\nlet key = generator.generate(1234567891011121314_u64);\n\n// Write the key in hex format to the console.\n// This will output something like: 112210F4B2D230A229552341B2E723\nprintln!(\"{}\", key.serialize::\u003cHexFormat\u003e());\n```\n\n# Verifying a license key\n\n```rust\nuse license_key::*;\n\n// Use the exact same hasher that we used when generating the key\nstruct DummyHasher { }\nimpl KeyHasher for DummyHasher {\n    fn hash(\u0026self, seed: u64, a: u64, b: u64, c: u64) -\u003e u8 {\n        ((seed ^ a ^ b ^ c) \u0026 0xFF) as u8\n    }\n}\n\n// Create the license key verifier\nlet mut verifier = Verifier::new(\n    DummyHasher { },\n    vec![\n        // Use the first byte (zero indexed) from the initialization vector.\n        // If a third-party key generator is created for the app, simply change this\n        // to another byte and any forged keys won't work anymore.\n        ByteCheck::new(0, (114, 83, 170)),\n    ],\n);\n\n// Block a specific seed.\n// You might want to do this if a key was leaked or the the \n// license key owner requested a refund.\nverifier.block(11111111_u64);\n\n// Parse a key in hex format\nlet key = LicenseKey::parse::\u003cHexFormat\u003e(\"112210F4B2D230A229552341E723\");\n\n// Verify the license key\nmatch verifier.verify(\u0026key) {\n    Status::Valid =\u003e println!(\"Key is valid!\"),\n    Status::Invalid =\u003e println!(\"Key is invalid!\"),\n    Status::Blocked =\u003e println!(\"Key has been blocked!\"),\n    Status::Forged =\u003e println!(\"Key has been forged!\"),\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatriksvensson%2Flicense-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatriksvensson%2Flicense-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatriksvensson%2Flicense-key/lists"}