Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(sdk): Adds brief usage code sample #26

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<dependency>
<groupId>io.opentdf/platform</groupId>
<artifactId>sdk</artifactId>
</dependency>
```



## 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)```
Loading