|
1 | 1 | # java-sdk
|
2 | 2 |
|
3 |
| -OpenTDF Java SDK |
| 3 | +This repository provides the OpenTDF Java SDK. |
| 4 | +It will be available from maven central as: |
4 | 5 |
|
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 | +} |
7 | 47 | ```
|
| 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 |
8 | 54 | static{
|
9 | 55 | Security.addProvider(new BouncyCastleProvider());
|
10 | 56 | }
|
11 | 57 | ```
|
12 | 58 |
|
13 | 59 | ### Logging
|
| 60 | + |
14 | 61 | We use [slf4j](https://www.slf4j.org/), without providing a backend. We use log4j2 in our tests.
|
15 | 62 |
|
16 | 63 | ### SSL - Untrusted Certificates
|
| 64 | + |
17 | 65 | Use the SDKBuilder.withSSL... methods to build an SDKBuilder with:
|
| 66 | + |
18 | 67 | - An SSLFactory: ```sdkBuilder.sslFactory(mySSLFactory)```
|
19 | 68 | - Directory containing trusted certificates: ```sdkBuilder.sslFactoryFromDirectory(myDirectoryWithCerts)```
|
20 | 69 | - Java Keystore: ```sdkBuilder.sslFactoryFromKeyStore(keystorepath, keystorePassword)```
|
0 commit comments