Library to access api.snailcrypt.com
To encrypt a string for a given date you can place the following code in your application:
```rust use snailcrypt::{ client, config, factory, util, };
use std::rc::Rc;
use chrono::{ DateTime, FixedOffset, };
/** * Setup main input data */ let plaintext = String::from("hello world"); let hint = String::from("This is a test message");
/**
* Produce a client
*/
let analyzerfactory: factory::AnalyzerFactory = factory::AnalyzerFactory::new();
let analyzer: Rc
let configfactory: factory::ConfigFactory = factory::ConfigFactory::new();
let config: Rc
let clientfactory: factory::ClientFactory = factory::ClientFactory::new(Rc::clone(&analyzer),
Rc::clone(&config));
let client: Rc
let lockdate: DateTime
/** * Perform encryption using the client */ let cipher: String = client.encrypt(&client::ClientEncryptArg { plaintext, lockdate, hint, }).unwraporelse(|error| { panic!("Error: {:?}", error); });
/**
* If you do not need a hint, then you can opt for a V1 client instead
*/
let clientv1: Rc
let cipherv1: String = clientv1.encrypt(&client::ClientEncryptArg { plaintext, lockdate, hint: String::from(""), }).unwraporelse(|error| { panic!("Error: {:?}", error); });
```
To decrypt a snailcrypt string you can place the following code in your application:
```rust use snailcrypt::{ client, config, factory, util, };
use std::rc::Rc;
use chrono::{ DateTime, FixedOffset, };
/** * Setup main input data */ let cipher: String = String::from("1:MjAyMi0xMS0xOVQxNzowMDowMCswMTAw:bVoPtqSST34ojbXQHEdTfQuvCgI7Ed/SsBLSNczVhoCSmMcpJNv3/rAGomn+hNJihmzOu7RQXDTNEnkewV4TXrMGuWqvfmCIAPTTQnuUkqLimuL8WD2Nu8LY2LaPMf3G1Q9JiRb+dd7lmboppgOd9ssPciAXTiI0NkJ4SawBW/PVWOuEFAWDs2MBkPT6oxbJrNha5L0lHDpgHMTP9HsdVf3gh9GiKuwQFtaZ3WXKTKUnOPALz3QkcLOspFHP+UuOUuZn4OrkxpWGbTFqS00NROwT4a5V0vbY/Ag+RYJtd9Pk3UsTT4QNUSj1vQ81X27tC6+B8gXxaVGWRynIgYn5wQ==");
/**
* Produce a client
*/
let analyzerfactory: factory::AnalyzerFactory = factory::AnalyzerFactory::new();
let analyzer: Rc
let configfactory: factory::ConfigFactory = factory::ConfigFactory::new();
let config: Rc
let clientfactory: factory::ClientFactory = factory::ClientFactory::new(Rc::clone(&analyzer),
Rc::clone(&config));
let client: Rc
/** * Perform decryption using the client */ let result = client .decrypt(cipher.asstr()) .unwraporelse(|error| { panic!("Error: {:?}", error.errormessage); });
println!("{}, result.plaintext.asstr());
println!("{}, result.hint.asstr());
```