@SuppressWarnings("UnusedException")
  public static byte[] serializeKeyset(KeysetHandle keysetHandle, SecretKeyAccess access)
      throws GeneralSecurityException {
    if (access == null) {
      throw new NullPointerException("SecretKeyAccess cannot be null");
    }
    try {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      CleartextKeysetHandle.write(keysetHandle, BinaryKeysetWriter.withOutputStream(outputStream));
      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