encrypt_simple/encrypt_simple.rs
1///////////////////////////////////////////////////////////////////////////////
2//
3// StringEncrypt WebApi interface usage example.
4//
5// In this example we will encrypt sample string with default options.
6//
7// Version : v1.0.0
8// Language : Rust
9// Author : Bartosz Wójcik
10// Project page : https://www.stringencrypt.com
11// Web page : https://www.pelock.com
12//
13///////////////////////////////////////////////////////////////////////////////
14
15use stringencrypt::{ErrorCode, StringEncrypt};
16
17#[tokio::main]
18async fn main() {
19 let mut string_encrypt = StringEncrypt::new("YOUR-API-KEY-HERE", false); // leave empty for demo mode
20
21 let result = string_encrypt
22 .encrypt_string("Hello!", "$label")
23 .await;
24
25 let Some(result) = result else {
26 println!("Cannot connect to the API.");
27 std::process::exit(1);
28 };
29
30 if result.error != Some(ErrorCode::SUCCESS as i64) {
31 println!("API error: {:?}", result.error);
32 std::process::exit(1);
33 }
34
35 println!("{}\n", result.source.unwrap_or_default());
36}