@SuppressWarnings("UnusedException")
  public static byte[] serializeEncryptedKeyset(
      KeysetHandle keysetHandle, Aead keysetEncryptionAead, byte[] associatedData)
      throws GeneralSecurityException {
    try {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      keysetHandle.writeWithAssociatedData(
          BinaryKeysetWriter.withOutputStream(outputStream), keysetEncryptionAead, associatedData);
      return outputStream.toByteArray();
    } catch (IOException e) {
      throw new GeneralSecurityException("Serialize keyset failed");
    }
  }
Functions to parse and serialize Keyset in Tink's binary format based on Protobufs.
java_src/src/main/java/com/google/crypto/tink/TinkProtoKeysetFormat.java