Sample code for 30+ languages & platforms
Rust

UN/EDIFACT Syntax Level A Encoding/Decoding

See more Encryption Examples

Demonstrates the new "eda" encoding that can be used throughout Chilkat starting in v9.5.0.65.

Chilkat Rust Downloads

Rust
// Note: Requires Chilkat v9.5.0.65 or greater.

let sb = chilkat::StringBuilder::new();
let _ = sb.append("The 5 men of 223rd St");
println!("{}", sb.get_as_string().unwrap_or_default());

// Encode the utf-8 byte representation of the string in the 
// UN/EDIFACT syntax level A character set.
let _ = sb.encode("eda", "utf-8");
println!("{}", sb.get_as_string().unwrap_or_default());

// EDA Output should be: BTME027FCF6CFARFI94JT6.)F(14KJ2U

// Decode back to the original string.
let _ = sb.decode("eda", "utf-8");
println!("{}", sb.get_as_string().unwrap_or_default());
println!("----");

// The following requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// The "eda" encoding can be used anywhere within Chilkat.
// For example, with the Crypt2 API
let crypt = chilkat::Crypt2::new();
crypt.set_crypt_algorithm("aes");
crypt.set_cipher_mode("cbc");
crypt.set_key_length(256);
crypt.set_encoding_mode("eda");

let iv_hex = "000102030405060708090A0B0C0D0E0F".to_string();
crypt.set_encoded_iv(&iv_hex, "hex");
let key_hex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F".to_string();
crypt.set_encoded_key(&key_hex, "hex");

let enc_str = crypt.encrypt_string_enc("The quick brown fox jumps over the lazy dog.").unwrap_or_default();
// The output is UN/EDIFACT syntax level A 
println!("{}", enc_str);

// Now decrypt:
let dec_str = crypt.decrypt_string_enc(&enc_str).unwrap_or_default();
println!("{}", dec_str);