@Theory
  public void multipleKeysReadKeyset_encryptDecryptDeterministically_success()
      throws Exception {
    KeysetHandle handle =
        TinkJsonProtoKeysetFormat.parseKeyset(
            JSON_DAEAD_KEYSET_WITH_MULTIPLE_KEYS, InsecureSecretKeyAccess.get());

    DeterministicAead daead = handle.getPrimitive(DeterministicAead.class);

    byte[] plaintext = "plaintext".getBytes(UTF_8);
    byte[] associatedData = "associatedData".getBytes(UTF_8);
    byte[] ciphertext = daead.encryptDeterministically(plaintext, associatedData);
    assertThat(daead.decryptDeterministically(ciphertext, associatedData)).isEqualTo(plaintext);

    // Also test that daead can decrypt ciphertexts encrypted with a non-primary key. We use
    // JSON_DAEAD_KEYSET to encrypt with the first key.
    KeysetHandle handle1 =
        TinkJsonProtoKeysetFormat.parseKeyset(JSON_DAEAD_KEYSET, InsecureSecretKeyAccess.get());
    DeterministicAead daead1 = handle1.getPrimitive(DeterministicAead.class);
    byte[] ciphertext1 = daead1.encryptDeterministically(plaintext, associatedData);
    assertThat(daead.decryptDeterministically(ciphertext1, associatedData)).isEqualTo(plaintext);
  }
Unit tests for the Daead package. Uses only the public API.
java_src/src/test/java/com/google/crypto/tink/daead/DaeadTest.java