Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

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

let crypt = chilkat::Crypt2::new();

// The "ps" is the WPA passphrase
let pw = "password".to_string();
let pw_charset = "ansi".to_string();

// Hash algorithms may be: sha1, md2, md5, etc.
let hash_alg = "sha1".to_string();

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

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

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

// Indicate that "hex" is to be returned.
let enc = "hex".to_string();

let wpa_hex_key = crypt.pbkdf2(&pw, &pw_charset, &hash_alg, &ssid_hex, iteration_count, output_bit_len, &enc).unwrap_or_default();

println!("{}", wpa_hex_key);