{"id":17271718,"url":"https://github.com/martinpaljak/cdoc4j","last_synced_at":"2025-04-14T08:20:31.128Z","repository":{"id":26919019,"uuid":"110213849","full_name":"martinpaljak/cdoc4j","owner":"martinpaljak","description":"Java library for handling CDOC 1.0/1.1/2.0 files with AES-256 GCM and RSA or ECC","archived":false,"fork":false,"pushed_at":"2024-10-04T11:50:49.000Z","size":450,"stargazers_count":3,"open_issues_count":9,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T21:52:04.776Z","etag":null,"topics":["aes-256","aes-gcm","cdoc","cryptography","encryption","java","xml"],"latest_commit_sha":null,"homepage":"","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/martinpaljak.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":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2017-11-10T06:58:10.000Z","updated_at":"2023-04-26T13:13:23.000Z","dependencies_parsed_at":"2022-08-07T12:01:17.294Z","dependency_job_id":null,"html_url":"https://github.com/martinpaljak/cdoc4j","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinpaljak%2Fcdoc4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinpaljak%2Fcdoc4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinpaljak%2Fcdoc4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinpaljak%2Fcdoc4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinpaljak","download_url":"https://codeload.github.com/martinpaljak/cdoc4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844036,"owners_count":21170505,"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":["aes-256","aes-gcm","cdoc","cryptography","encryption","java","xml"],"created_at":"2024-10-15T08:46:30.268Z","updated_at":"2025-04-14T08:20:31.100Z","avatar_url":"https://github.com/martinpaljak.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cdoc4j · [![Build Status](https://github.com/martinpaljak/cdoc4j/workflows/Release%20CI/badge.svg)](https://github.com/martinpaljak/cdoc4j/actions)  [![Release](https://img.shields.io/github/release/martinpaljak/cdoc4j/all.svg)](https://github.com/martinpaljak/cdoc4j/releases) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.martinpaljak/cdoc4j/badge.svg)](https://mvnrepository.com/artifact/com.github.martinpaljak/cdoc4j) [![Javadocs](https://www.javadoc.io/badge/com.github.martinpaljak/cdoc4j.svg)](https://www.javadoc.io/doc/com.github.martinpaljak/cdoc4j) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/martinpaljak/cdoc4j/blob/master/LICENSE)\n\nSmall Java library for handling CDOC encryption format, with Elliptic Curve support (\"CDOC 1.1 amendment\").\n\nFor working with CDOC files from the command line, use the [cdoc utility](https://github.com/martinpaljak/cdoc).\n\n### Supported formats\n- [CDOC 1.0](https://github.com/martinpaljak/cdoc/wiki/CDOC-1.0): AES-128 CBC, *RSA recipients only*, XML base64 container (supported by [@open-eid](https://github.com/open-eid) software)\n- **[CDOC 1.1](https://github.com/martinpaljak/cdoc4j/blob/master/docs/CDOC-A-101-7.pdf) (default):** AES-256 GCM, RSA and ECC recipients, XML base64 container (supported _soon_ by [@open-eid](https://github.com/open-eid) software)\n- [CDOC 2.0](FORMAT.md): AES-256 GCM, RSA and ECC recipients, ZIP container (_at least_ 30%, usually 50% smaller files compared to XML, not (yet) supported by @open-eid software)\n\n----\n\n- Include dependency\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.martinpaljak\u003c/groupId\u003e\n    \u003cartifactId\u003ecdoc4j\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.8\u003c/version\u003e\n\u003c/dependency\u003e\n```\n- **When using Oracle Java, make sure you have [\"Unlimited Strength Jurisdiction Policy Files\"](https://github.com/martinpaljak/cdoc/wiki/UnlimitedCrypto) installed!**\n- Get coding!\n\n## Creating CDOC files\n```java\nimport org.cdoc4j.CDOCBuilder;\nimport static org.cdoc4j.CDOC.VERSION.CDOC_V2_0;\n\n// 0. Create the builder\nCDOCBuilder builder = CDOC.builder();\n// Override default CDOC 1.1 version\nbuilder.setVersion(CDOC_V2_0);\n\n// 1. Where to write the output\nbuilder.setOutputStream(new FileOutputStream(\"output.cdoc\"));\n\n// 2. Set recipients\nX509Certificate cert = ...\nbuilder.addRecipient(cert);\n\n// 3. For legacy XML containers, add files via any of the following methods\nbuilder.addStream(\"test1.txt\", new URL(\"http://www.example.com/test1.txt\")); // or ByteArrayInputStream\nbuilder.addFile(new File(\"test2.txt\"));\nbuilder.addPath(Paths.get(\"test3.txt\"));\nbuilder.build(); // Writes it to output stream\nbuilder.buildToStream(new FileOutputStream(\"otherfile.cdoc\"));\n```\n\n## Opening CDOC files\n```java\nimport CDOC;\n\n// 1. Either from a file\nCDOC cdoc = CDOC.open(new File(\"test.cdoc\"));\n\n// 2. Or from an InputStream\nInputStream input = new URL(\"http://example.com/sample.cdoc\").openStream();\nCDOC cdoc = CDOC.from(input);\n\n// 3. Once the file has been opened, get recipients \nList\u003cRecipient\u003e recipients = cdoc.getRecipients();\n\n// 4. Information in a Recipient object allows to construct the transport key for decryption\nKeyPair kp = ...\nSecretKey key = Decrypt.getKey(kp, recipients.get(0));\n\n// 5. Knowing the transport key allows to access the encrypted files\nMap\u003cString, byte[]\u003e files = cdoc.getFiles(key); // Can consume a lot of memory with large files\n```\n\n## ~~CDOC 2.0 and streams~~ (Work in Progress)\nCDOC 2.0 is designed to be more resource efficient and flexible than CDOC 1.x. CDOC 2.0 is a standard ODF ZIP container with an inner ZIP file, which allows to use standard Java [ZipInputStream](https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipInputStream.html)/[ZipOutputStream](https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipOutputStream.html) interfaces. This way you can easily encrypt and decrypt files with sizes in several gigabytes without running out of memory.\n\n```java\n// To open the payload as a ZipInputStream\nZipInputStream zip = cdoc.getZipInputStream(key);\n\n// To add files via ZipOutputStream\nZipOutputStream zip = CDOC.builder(CDOC_V2_0).addRecipient(...).buildZipOutputStream();\nzip.putNextEntry(new ZipEntry(\"test.txt\"));\nIOUtils.copy(new InputSream(...), zip);\nzip.closeEntry();\nzip.close();\n```\n\n## Notes and caveats\n* CDOC 1.X uses XML and in-memory processing of Base64 data, which requires a lot of memory. Thus it is advisable to only encrypt small files (in the range of 1M..100M, not 100M..1G) into v1.X formats and to make sure that enough memory is available to the JVM (`-Xmx8g`)\n\n## Dependencies\n- [BouncyCastle](https://www.bouncycastle.org) (MIT)\n- [Apache Commons IO](https://commons.apache.org/io/) (Apache)\n- [slf4j](https://www.slf4j.org/) (MIT)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinpaljak%2Fcdoc4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinpaljak%2Fcdoc4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinpaljak%2Fcdoc4j/lists"}