@Test
  public void kmsAeadGrpc_works() throws Exception {
    String keyName = "projects/cloudkms-test/locations/global/keyRings/TinkKmsLib/cryptoKeys/key1";
    Aead kmsAead =
        GcpKmsAead.builder().setKeyName(keyName).setKeyManagementServiceClient(kmsClient).build();

    byte[] plaintext = "plaintext".getBytes(UTF_8);
    byte[] associatedData = "associatedData".getBytes(UTF_8);
    byte[] associatedData2 = "associatedData2".getBytes(UTF_8);
    byte[] ciphertext = kmsAead.encrypt(plaintext, associatedData);
    byte[] decrypted = kmsAead.decrypt(ciphertext, associatedData);

    assertThat(decrypted).isEqualTo(plaintext);
    assertThrows(
        GeneralSecurityException.class, () -> kmsAead.decrypt(ciphertext, associatedData2));
    ciphertext[7] = (byte) (ciphertext[7] ^ 42);
    assertThrows(GeneralSecurityException.class, () -> kmsAead.decrypt(ciphertext, associatedData));
  }
This rule manages automatic graceful shutdown for the registered servers and channels.
java_src/src/test/java/com/google/crypto/tink/integration/gcpkms/GcpKmsAeadTest.java