Zig
Zig
Base64 Encode/Decode a String
See more Encryption Examples
_LANGUAGE_ example to base-64 encode and decode a string.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const bd = try chilkat.BinData.init();
defer bd.deinit();
const s = "A friend called me up the other day and talked about investing in a dot-com that sells lobsters. Internet lobsters. Where will this end? --Donald Trump";
try bd.appendString(s, "utf-8");
const str_base64 = try bd.getEncoded(alloc, "base64");
std.debug.print("{s}\n", .{str_base64});
// To decode:
const bd2 = try chilkat.BinData.init();
defer bd2.deinit();
bd2.appendEncoded(str_base64, "base64") catch {};
const decoded = try bd2.getString(alloc, "utf-8");
std.debug.print("{s}\n", .{decoded});
}