Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Stdlib

Encoding — Base64, URL, HTML

string Convert.ToBase64String(bytes) · Uri.EscapeDataString(s) · WebUtility.HtmlEncode(s)

Encode and decode text — Base64, URL percent-encoding, and HTML escaping — with the C#-faithful spellings. `Convert.ToBase64String` / `FromBase64String` for binary, `Uri.EscapeDataString` / `UnescapeDataString` for URLs, `WebUtility.HtmlEncode` / `HtmlDecode` for HTML. All pure — no capability needed.

stable3 examples compiled by CIencodingbase64urlhtml

Summary#

Three small encoding surfaces, spelled exactly as in C#, all pure (no capability, no using required):

var b64  = Convert.ToBase64String(bytes);          // binary  → base64 text
var back = Convert.FromBase64String(b64);          // base64  → binary
var q    = Uri.EscapeDataString("a b&c");          // "a%20b%26c" — safe in a URL
var safe = WebUtility.HtmlEncode("<b>hi</b>");      // "&lt;b&gt;hi&lt;/b&gt;" — safe in HTML text

Signature#

string  Convert.ToBase64String(byte[] bytes)     // Binary → base64 text
byte[]  Convert.FromBase64String(string s)       // base64 text → Binary
string  Uri.EscapeDataString(string s)           // percent-encode for a URL
string  Uri.UnescapeDataString(string s)         // reverse
string  WebUtility.HtmlEncode(string s)          // escape for HTML text
string  WebUtility.HtmlDecode(string s)          // reverse

Description#

Base64Convert.ToBase64String turns a Binary value (bytes, e.g. a file read via <span class="planned" title="this page is planned and not written yet">storage-file</span> or a Binary property) into standard base64 text; Convert.FromBase64String reverses it. Use it to carry bytes inside a JSON body or a text field.

URL escapingUri.EscapeDataString percent-encodes a string so it is safe inside a URL query value or path segment (RFC 3986: a space becomes %20, & becomes %26, and so on). Uri.UnescapeDataString reverses it. Pair it with Http.* when building a request URL from user input:

var url = "https://api.example.com/search?q=" + Uri.EscapeDataString(term);

HTML escapingWebUtility.HtmlEncode escapes &, <, >, " so a string is safe to place in HTML text without injecting markup; WebUtility.HtmlDecode reverses it.

Not yet available. Raw UTF-8 byte conversion (Encoding.UTF8.GetBytes / GetString) is a planned follow-on — Base64 already carries bytes as text, and JSON round-trips byte[] as base64 automatically. Ask for it when you need raw UTF-8 bytes directly.

Examples#

Build a signed-looking token payload as base64:

string Encode(byte[] payload) {
  return Convert.ToBase64String(payload);
}

byte[] Decode(string base64) {
  return Convert.FromBase64String(base64);
}

Escape user input into an outbound request (Http.*):

app Shop {
  model "model/**/*.osy";
  use Osyrin.Http;         // `use` is a MANIFEST declaration — it belongs in app.osy
}

string Search(string term) {
  var url = "https://api.example.com/search?q=" + Uri.EscapeDataString(term);
  var r = Http.Get(url);
  return r.Body;
}

Render user text safely into an HTML fragment:

string Cell(string userText) {
  return "<td>" + WebUtility.HtmlEncode(userText) + "</td>";
}

See also#

  • Uri — parse a URL into its parts (new Uri(url).Host)
  • Regex — pattern matching, replacing, and splitting text
  • Http.* — the outbound HTTP surface these escapings feed

Related

Uri

Parse a URL into its parts with the C#-faithful `new Uri(url)` handle. Construct it from a URL string, then read…

Regex

Match, replace, split and CAPTURE with regular expressions — the C#-faithful System.Text.RegularExpressions spelling…

Http.*

Make an outbound HTTP call to a URL you build at runtime — a webhook, a third-party API, a discovered endpoint…