@Test
  public void serializeAndParse_decrypts() throws Exception {
    Parameters aesGcm128Parameters = MyCustomKeyManager.aesGcm128Parameters();
    KeysetHandle handle = KeysetHandle.generateNew(aesGcm128Parameters);
    Aead aead = handle.getPrimitive(Aead.class);
    byte[] plaintext = "plaintext".getBytes(UTF_8);
    byte[] associatedData = "associatedData".getBytes(UTF_8);
    byte[] ciphertext = aead.encrypt(plaintext, associatedData);

    byte[] serializedKeyset =
        TinkProtoKeysetFormat.serializeKeyset(handle, InsecureSecretKeyAccess.get());

    KeysetHandle handle2 =
        TinkProtoKeysetFormat.parseKeyset(serializedKeyset, InsecureSecretKeyAccess.get());
    Aead aead2 = handle2.getPrimitive(Aead.class);
    byte[] decrypted = aead2.decrypt(ciphertext, associatedData);
    assertThat(decrypted).isEqualTo(plaintext);
  }
A custom implementation of {@link com.google.crypto.tink.KeyManager} for AES GCM 128.

<p>It only implements the methods of the KeyManager interface that are needed.
java_src/src/test/java/com/google/crypto/tink/custom/CustomAeadKeyManagerTest.java