Sample code for 30+ languages & platforms
Zig

WPA Key Calculation from PassPhrase to Hex

See more Encryption Examples

Demonstrates how to calculate a WPA key from a passprhase and network SSID.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const crypt = try chilkat.Crypt2.init();
    defer crypt.deinit();

    // The "ps" is the WPA passphrase
    const pw = "password";
    const pw_charset = "ansi";

    // Hash algorithms may be: sha1, md2, md5, etc.
    const hash_alg = "sha1";

    // Specify the SSID in hex:
    // For example, if the SSID is "ABC", then the
    // hex values for these us-ascii chars is "414243"
    const ssid_hex = "414243";

    // The WPA key calculation will always use 4096 iterations.
    const iteration_count = 4096;

    // The WPA hex output should be 256 bits.
    const output_bit_len = 256;

    // Indicate that "hex" is to be returned.
    const enc = "hex";

    const wpa_hex_key = try crypt.pbkdf2(alloc, pw, pw_charset, hash_alg, ssid_hex, iteration_count, output_bit_len, enc);

    std.debug.print("{s}\n", .{wpa_hex_key});
}