Skip to content

Commit 70813fc

Browse files
docs(core): Adds usage to README
- Adds a quick code sample for creating/reading TDFs - Other fixes
1 parent 8bade49 commit 70813fc

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

README.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,69 @@
11
# java-sdk
22

3-
OpenTDF Java SDK
3+
This repository provides the OpenTDF Java SDK.
4+
It will be available from maven central as:
45

5-
### SDK Usage
6-
The SDK uses the [Bouncy Castle Security library](https://www.bouncycastle.org/). SDK users may need to register the Bouncy Castle Provider; e.g.:
6+
```xml
7+
<dependency>
8+
<groupId>io.opentdf/platform</groupId>
9+
<artifactId>sdk</artifactId>
10+
</dependency>
11+
```
12+
13+
14+
15+
## SDK Usage
16+
17+
### TDF File Creation and Reading
18+
19+
```java
20+
import io.opentdf.platform.sdk.Config;
21+
import io.opentdf.platform.sdk.SDK;
22+
import io.opentdf.platform.sdk.SDKBuilder;
23+
import io.opentdf.platform.sdk.abac.Policy;
24+
import java.io.InputStream;
25+
import java.io.FileInputStream;
26+
27+
public class Example {
28+
public static void main(String args[]) {
29+
SDK sdk =
30+
new SDKBuilder
31+
.clientSecret("myClient", "token")
32+
.platformEndpoint("https://your.cluster/")
33+
.build();
34+
// Encrypt a file
35+
try (InputStream in = new FileInputStream("input.plaintext")) {
36+
Config c = Config.newTDFConfig(Config.withDataAttributes("attr1", "attr2"))
37+
new TDF().createTDF(in, System.out, tdfConfig, sdk.getServices().kas());
38+
}
39+
40+
// Decrypt a file
41+
try (SeekableByteChannel in =
42+
FileChannel.open("input.ciphertext", StandardOpenOption.READ)) {
43+
TDF.Reader reader = new TDF().loadTDF(in, sdk.getServices().kas());
44+
reader.readPayload(System.out);
45+
}
46+
}
747
```
48+
49+
### Cryptography Library
50+
51+
The SDK uses the [Bouncy Castle Security library](https://www.bouncycastle.org/). SDK users may need to register the Bouncy Castle Provider; e.g.:
52+
53+
```java
854
static{
955
Security.addProvider(new BouncyCastleProvider());
1056
}
1157
```
1258

1359
### Logging
60+
1461
We use [slf4j](https://www.slf4j.org/), without providing a backend. We use log4j2 in our tests.
1562

1663
### SSL - Untrusted Certificates
64+
1765
Use the SDKBuilder.withSSL... methods to build an SDKBuilder with:
66+
1867
- An SSLFactory: ```sdkBuilder.sslFactory(mySSLFactory)```
1968
- Directory containing trusted certificates: ```sdkBuilder.sslFactoryFromDirectory(myDirectoryWithCerts)```
2069
- Java Keystore: ```sdkBuilder.sslFactoryFromKeyStore(keystorepath, keystorePassword)```

0 commit comments

Comments
 (0)