Zig
Zig
Set the JWE Protected Header
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.SetProtectedHeader, which sets the integrity-protected JWE header from a JsonObject. The header specifies the key-management algorithm (alg) and content-encryption algorithm (enc).
Background. The protected header is integrity-protected and applies to all recipients. It is configured before encrypting.
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 jwe = try chilkat.Jwe.init();
defer jwe.deinit();
// Build the JWE protected header. The "alg" member names the key-management algorithm and the "enc"
// member names the content-encryption algorithm.
const header = try chilkat.JsonObject.init();
defer header.deinit();
header.updateString("alg", "A256KW") catch {};
header.updateString("enc", "A256GCM") catch {};
// Set the protected header on the JWE. The protected header is integrity-protected and applies to
// all recipients.
jwe.setProtectedHeader(header) catch {
std.debug.print("{s}\n", .{try jwe.getLastErrorText(alloc)});
return;
};
std.debug.print("Protected header set.\n", .{});
}