Skip to content

Commit

Permalink
docs(sdk): Adds brief usage code sample (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Jun 18, 2024
1 parent 8bade49 commit 79215c7
Showing 1 changed file with 52 additions and 3 deletions.
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)```

0 comments on commit 79215c7

Please sign in to comment.