-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(sdk): Adds brief usage code sample (#26)
- Loading branch information
1 parent
8bade49
commit 79215c7
Showing
1 changed file
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)``` |