First go to plugin docs and add it to your project
Aragon create used:
https://crates.io/crates/rust-argon2
src-tauri/main.rs
use argon2::{ Config, ThreadMode, Variant, Version, hash_raw };
fn main (){
tauri::Builder::default()
.plugin(tauri_plugin_stronghold::Builder::new(move |password| {
// Aragon config
let config = Config {
lanes : 4,
mem_cost : 10_000,
time_cost : 10,
thread_mode : ThreadMode::from_threads(4),
variant : Variant::Argon2id,
version : Version::Version13,
..Default::default()
};
// hash password
let key = hash_raw(password.as_ref(), "my-salt".as_bytes(), &config).expect("failed to hash password");
// return the hash
key.to_vec()
}).build())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
client/main.js
import { Stronghold } from "tauri-plugin-stronghold-api";
// Load Stronghold
const password = "my_pass"; // your Stronghold (to open it)
const fullPath = "my/path/to/stronghold"; // should be your app_data dir
const stronghold = await Stronghold.load(fullPath, password)
// Create or Load a client
const client_name = "my_client";
const client = await stronghold.createClient(client_name).getStore()
// or
const client = await stronghold.loadClient(client_name).getStore()
// EXAMPLE DATA
const DATA = {
key : "my-key",
value : "my-super-secret",
}
// Read data
const value = await client.get(DATA.key);
const decoded = new TextDecoder().decode(new Uint8Array(value ?? []));
// Write data
await client.insert(DATA.key, Array.from(new TextEncoder().encode(DATA.value)));
// Save written data
await stronghold.save();
// Close Database
await stronghold.unload();