From 70813fc7bb77c1b9abce09e8a0ddf14789a6c097 Mon Sep 17 00:00:00 2001 From: David Mihalcik Date: Tue, 16 Apr 2024 22:44:03 -0400 Subject: [PATCH] docs(core): Adds usage to README - Adds a quick code sample for creating/reading TDFs - Other fixes --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 81cf2a6f..badf4609 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,69 @@ # java-sdk -OpenTDF Java SDK +This repository provides the OpenTDF Java SDK. +It will be available from maven central as: -### SDK Usage -The SDK uses the [Bouncy Castle Security library](https://www.bouncycastle.org/). SDK users may need to register the Bouncy Castle Provider; e.g.: +```xml + + io.opentdf/platform + sdk + +``` + + + +## SDK Usage + +### TDF File Creation and Reading + +```java +import io.opentdf.platform.sdk.Config; +import io.opentdf.platform.sdk.SDK; +import io.opentdf.platform.sdk.SDKBuilder; +import io.opentdf.platform.sdk.abac.Policy; +import java.io.InputStream; +import java.io.FileInputStream; + +public class Example { + public static void main(String args[]) { + SDK sdk = + new SDKBuilder + .clientSecret("myClient", "token") + .platformEndpoint("https://your.cluster/") + .build(); + // Encrypt a file + try (InputStream in = new FileInputStream("input.plaintext")) { + Config c = Config.newTDFConfig(Config.withDataAttributes("attr1", "attr2")) + new TDF().createTDF(in, System.out, tdfConfig, sdk.getServices().kas()); + } + + // Decrypt a file + try (SeekableByteChannel in = + FileChannel.open("input.ciphertext", StandardOpenOption.READ)) { + TDF.Reader reader = new TDF().loadTDF(in, sdk.getServices().kas()); + reader.readPayload(System.out); + } +} ``` + +### Cryptography Library + +The SDK uses the [Bouncy Castle Security library](https://www.bouncycastle.org/). SDK users may need to register the Bouncy Castle Provider; e.g.: + +```java static{ Security.addProvider(new BouncyCastleProvider()); } ``` ### Logging + We use [slf4j](https://www.slf4j.org/), without providing a backend. We use log4j2 in our tests. ### SSL - Untrusted Certificates + Use the SDKBuilder.withSSL... methods to build an SDKBuilder with: + - An SSLFactory: ```sdkBuilder.sslFactory(mySSLFactory)``` - Directory containing trusted certificates: ```sdkBuilder.sslFactoryFromDirectory(myDirectoryWithCerts)``` - Java Keystore: ```sdkBuilder.sslFactoryFromKeyStore(keystorepath, keystorePassword)```