Zig
Zig
Load EC Public Key from X,Y Values
See more ECC Examples
Demonstrates how to load an EC public key from X and Y values.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// We have the following x and y values in base64 (for an EC point on the P-256 curve).
const x = "Dn7uB1O7kgk74G6qfQwFJESeDnxO6lLjGZFWZJE16tw";
const y = "iOWA5DInzK6nuUGvHJbMVq1Dpj248FqSV2teN3HzmhU";
// Build a JWK that looks like this:
// {
// "kty": "EC",
// "crv": "P-256",
// "x": "Dn7uB1O7kgk74G6qfQwFJESeDnxO6lLjGZFWZJE16tw",
// "y": "iOWA5DInzK6nuUGvHJbMVq1Dpj248FqSV2teN3HzmhU"
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("kty", "EC") catch {};
json.updateString("crv", "P-256") catch {};
json.updateString("x", x) catch {};
json.updateString("y", y) catch {};
// Load from the JWK.
const pubkey = try chilkat.PublicKey.init();
defer pubkey.deinit();
pubkey.loadFromString(try json.emit(alloc)) catch {
std.debug.print("{s}\n", .{try pubkey.getLastErrorText(alloc)});
return;
};
std.debug.print("Success.\n", .{});
}