{"id":20366001,"url":"https://github.com/altcha-org/altcha-lib-java","last_synced_at":"2025-09-23T17:32:03.657Z","repository":{"id":250605149,"uuid":"834924273","full_name":"altcha-org/altcha-lib-java","owner":"altcha-org","description":"A lightweight Java library for creating and verifying ALTCHA challenges.","archived":false,"fork":false,"pushed_at":"2025-06-07T05:19:58.000Z","size":41,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T03:44:13.937Z","etag":null,"topics":["altcha","java"],"latest_commit_sha":null,"homepage":"https://altcha.org/","language":"Java","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/altcha-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2024-07-28T18:16:28.000Z","updated_at":"2025-06-07T05:19:55.000Z","dependencies_parsed_at":"2025-01-15T04:03:15.686Z","dependency_job_id":"30d1ec9b-6cf3-4bb4-9185-34126528eb5d","html_url":"https://github.com/altcha-org/altcha-lib-java","commit_stats":null,"previous_names":["altcha-org/altcha-lib-java"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/altcha-org/altcha-lib-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altcha-org","download_url":"https://codeload.github.com/altcha-org/altcha-lib-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276616770,"owners_count":25674145,"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","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["altcha","java"],"created_at":"2024-11-15T00:21:45.210Z","updated_at":"2025-09-23T17:32:03.650Z","avatar_url":"https://github.com/altcha-org.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ALTCHA Java Library\n\nThe ALTCHA Java Library is a lightweight library designed for creating and verifying [ALTCHA](https://altcha.org) challenges.\n\n## Compatibility\n\nThis library is compatible with:\n\n- Java 8+\n\n## Example\n\n- [Demo server](https://github.com/altcha-org/altcha-starter-java)\n\n## Installation\n\nMaven Central: [org.altcha/altcha](https://central.sonatype.com/artifact/org.altcha/altcha)\n\nMaven:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.altcha\u003c/groupId\u003e\n    \u003cartifactId\u003ealtcha\u003c/artifactId\u003e\n    \u003cversion\u003e1.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nGradle:\n\n\n```\nimplementation 'org.altcha:altcha:1.2.0'\n```\n\n## Random Number Generator\n\nBy default, this library uses a non-secure random number generator to avoid problems with insufficient noise. To enforce the use of a secure random number generator, set `secureRandomNumber` to `true` in the `ChallengeOptions` when generating a new challenge.\n\nIf you find that the generator is slow or hangs due to insufficient entropy, you can add the following JVM option to your invocation:\n\n```\n-Djava.security.egd=file:/dev/./urandom\n```\n\nThis option forces the JVM to use `/dev/urandom` for generating random numbers, which can help resolve issues related to entropy.\n\n## Usage\n\nHere’s a basic example of how to use the ALTCHA Java Library:\n\n```java\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport org.altcha.altcha.Altcha;\nimport org.altcha.altcha.Altcha.ChallengeOptions;\n\npublic class Example {\n    public static void main(String[] args) {\n        String hmacKey = \"secret hmac key\";\n\n        try {\n            // Create a new challenge\n            ChallengeOptions options = new ChallengeOptions()\n                .setMaxNumber(100000L) // the maximum random number\n                .setHmacKey(hmacKey)\n                .setExpiresInSeconds(3600) // 1 hour expiration\n\n            System.out.println(\"Challenge created: \" + challenge);\n\n            // Example payload to verify\n            Map\u003cString, Object\u003e payload = new HashMap\u003c\u003e();\n            payload.put(\"algorithm\", challenge.algorithm);\n            payload.put(\"challenge\", challenge.challenge);\n            payload.put(\"number\", 12345); // Example number\n            payload.put(\"salt\", challenge.salt);\n            payload.put(\"signature\", challenge.signature);\n\n            // Verify the solution\n            boolean isValid = Altcha.verifySolution(payload, hmacKey, true);\n\n            if (isValid) {\n                System.out.println(\"Solution verified!\");\n            } else {\n                System.out.println(\"Invalid solution.\");\n            }\n\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}\n```\n\n## API\n\n### `createChallenge(ChallengeOptions options)`\n\nCreates a new challenge for ALTCHA.\n\n**Parameters:**\n\n- `ChallengeOptions options`: Options for creating the challenge.\n\n**Returns:** `Challenge`\n\n### `verifySolution(Payload payload, String hmacKey, boolean checkExpires)`\n\nVerifies an ALTCHA solution using a `Payload` object.\n\n**Parameters:**\n\n- `Payload payload`: The solution payload to verify.\n- `String hmacKey`: The HMAC key used for verification.\n- `boolean checkExpires`: Whether to check if the challenge has expired.\n\n**Returns:** `boolean`\n\n### `verifySolution(String base64Payload, String hmacKey, boolean checkExpires)`\n\nVerifies an ALTCHA solution using a base64-encoded JSON string.\n\n**Parameters:**\n\n- `String base64Payload`: Base64-encoded JSON payload to verify.\n- `String hmacKey`: The HMAC key used for verification.\n- `boolean checkExpires`: Whether to check if the challenge has expired.\n\n**Returns:** `boolean`\n\n### `extractParams(String salt)`\n\nExtracts URL parameters from the salt.\n\n**Parameters:**\n\n- `String salt`: The salt string containing URL parameters.\n\n**Returns:** `Map\u003cString, String\u003e`\n\n### `verifyFieldsHash(Map\u003cString, String\u003e formData, List\u003cString\u003e fields, String fieldsHash, Algorithm algorithm)`\n\nVerifies the hash of form fields.\n\n**Parameters:**\n\n- `Map\u003cString, String\u003e formData`: The form data to hash.\n- `List\u003cString\u003e fields`: The fields to include in the hash.\n- `String fieldsHash`: The expected hash value.\n- `Algorithm algorithm`: Hashing algorithm (`SHA-1`, `SHA-256`, `SHA-512`).\n\n**Returns:** `boolean`\n\n### `verifyServerSignature(ServerSignaturePayload payload, String hmacKey)`\n\nVerifies the server signature using a `ServerSignaturePayload` object.\n\n**Parameters:**\n\n- `ServerSignaturePayload payload`: The payload to verify.\n- `String hmacKey`: The HMAC key used for verification.\n\n**Returns:** `boolean, ServerSignatureVerificationData`\n\n### `verifyServerSignature(String base64Payload, String hmacKey)`\n\nVerifies the server signature using a base64-encoded JSON string.\n\n**Parameters:**\n\n- `String base64Payload`: Base64-encoded JSON payload to verify.\n- `String hmacKey`: The HMAC key used for verification.\n\n**Returns:** `boolean, ServerSignatureVerificationData`\n\n### `solveChallenge(String challenge, String salt, Algorithm algorithm, int max, int start)`\n\nFinds a solution to the given challenge.\n\n**Parameters:**\n\n- `String challenge`: The challenge hash.\n- `String salt`: The challenge salt.\n- `Algorithm algorithm`: Hashing algorithm (`SHA-1`, `SHA-256`, `SHA-512`).\n- `int max`: Maximum number to iterate to.\n- `int start`: Starting number.\n\n**Returns:** `Solution`\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltcha-org%2Faltcha-lib-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-java/lists"}