@Test
  public void keysetWithCustomAndTinkKeys_decrypts() throws Exception {
    byte[] rawAesKey = Random.randBytes(16);
    Aead jceAead = new AesGcmJce(rawAesKey);
    byte[] plaintext = "plaintext".getBytes(UTF_8);
    byte[] associatedData = "associatedData".getBytes(UTF_8);
    byte[] ciphertext = jceAead.encrypt(plaintext, associatedData);

    // Create keyset handle with normal Tink key
    KeysetHandle handleWithTinkKey =
        KeysetHandle.generateNew(
            ChaCha20Poly1305Parameters.create(ChaCha20Poly1305Parameters.Variant.TINK));
    Aead aead2 = handleWithTinkKey.getPrimitive(Aead.class);
    byte[] ciphertext2 = aead2.encrypt(plaintext, associatedData);

    KeysetHandle handle =
        MyCustomKeyManager.aesGcm128KeyToKeysetHandle(
            rawAesKey, /* keyId= */ 0x11223344, OutputPrefixType.RAW);
    // Create keyset handle with both the custom key and the normal Tink key
    KeysetHandle handle2 =
        KeysetHandle.newBuilder(handle)
            .addEntry(KeysetHandle.importKey(handleWithTinkKey.getAt(0).getKey()).makePrimary())
            .build();

    // Decrypt both ciphertexts
    Aead aead = handle2.getPrimitive(Aead.class);
    assertThat(aead.decrypt(ciphertext, associatedData)).isEqualTo(plaintext);
    assertThat(aead.decrypt(ciphertext2, associatedData)).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