Zig
Zig
Generate Salt in Hex or Base64 Format
See more Encryption Examples
Demonstrates how to generate a cryptographic salt value and get the result as hex or base64.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// In cryptography, a salt is random data that is used as an additional input to a one-way function that "hashes" data, a password or passphrase.
// Let's say we want to generate a 16-byte salt value..
const prng = try chilkat.Prng.init();
defer prng.deinit();
const salt_hex = try prng.genRandom(alloc, 16, "hex");
std.debug.print("16-byte salt as hex: {s}\n", .{salt_hex});
const salt_base64 = try prng.genRandom(alloc, 16, "base64");
std.debug.print("16-byte salt as base64: {s}\n", .{salt_base64});
}