Rust
Rust
Quoted-Printable Encode/Decode a String
See more Encryption Examples
_LANGUAGE_ example to quoted-printable encode and decode a string.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let crypt = chilkat::Crypt2::new();
// Here's a string in Icelandic using non us-ascii chars:
let s = "Ég get etið gler án þess að meiða mig.".to_string();
crypt.set_crypt_algorithm("none");
crypt.set_encoding_mode("quoted-printable");
// Quoted-printable encode/decode the iso-8859-1
// representation of the string. Notice how each
// Icelandic char is represented by 1 byte:
crypt.set_charset("iso-8859-1");
let qp = crypt.encrypt_string_enc(&s).unwrap_or_default();
println!("iso-8859-1:");
println!("{}", qp);
let decoded = crypt.decrypt_string_enc(&qp).unwrap_or_default();
println!("{}", decoded);
// Now do the same using utf-8. Notice how each
// Icelandic char is represented by 2 bytes in utf-8:
crypt.set_charset("utf-8");
let qp = crypt.encrypt_string_enc(&s).unwrap_or_default();
println!("utf-8:");
println!("{}", qp);
let decoded = crypt.decrypt_string_enc(&qp).unwrap_or_default();
println!("{}", decoded);