Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Updating the Java HOWTO to include sample code for DeterministicAead.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 193437447
GitOrigin-RevId: f9e0c3d9f88297cca3de81120836c9fc88020c6e
  • Loading branch information
thaidn committed Apr 19, 2018
1 parent 3904920 commit 7e44262
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions doc/JAVA-HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,8 @@ factory offers corresponding `getPrimitive(...)` methods.
### Symmetric Key Encryption

Here is how you can obtain and use an [AEAD (Authenticated Encryption with
Associated
Data](PRIMITIVES.md#authenticated-encryption-with-associated-data) primitive
to encrypt or decrypt data:
Associated Data](PRIMITIVES.md#authenticated-encryption-with-associated-data)
primitive to encrypt or decrypt data:

```java
import com.google.crypto.tink.Aead;
Expand All @@ -305,6 +304,34 @@ to encrypt or decrypt data:
byte[] decrypted = aead.decrypt(ciphertext, aad);
```

### Deterministic Symmetric Key Encryption

Here is how you can obtain and use an [DeterministicAEAD (Deterministic
Authenticated Encryption with Associated
Data](PRIMITIVES.md#deterministic-authenticated-encryption-with-associated-data)
primitive to encrypt or decrypt data:

```java
import com.google.crypto.tink.DeterministicAead;
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.daead.DeterministicAeadFactory;
import com.google.crypto.tink.daead.DeterministicAeadKeyTemplates;

// 1. Generate the key material.
KeysetHandle keysetHandle = KeysetHandle.generateNew(
DeterministicAeadKeyTemplates.AES256_SIV);

// 2. Get the primitive.
DeterministicAead daead =
DeterministicAeadFactory.getPrimitive(keysetHandle);

// 3. Use the primitive to deterministically encrypt a plaintext,
byte[] ciphertext = daead.encryptDeterministically(plaintext, aad);

// ... or to deterministically decrypt a ciphertext.
byte[] decrypted = daead.decryptDeterministically(ciphertext, aad);
```

### Symmetric Key Encryption of Streaming Data

Here is how you can obtain and use an [Streaming AEAD (Streaming Authenticated Encryption with
Expand Down

0 comments on commit 7e44262

Please sign in to comment.