1 Star 0 Fork 0

itooling/rskit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
cc kit d5d49d1 3个月前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

rust kit

cache

You can use cache to store data and support multi-threaded sharing.

let cache = rskit::cache::Cache::new();
cache.set("name", "iclings");
let name = cache.get::<&str>("name").unwrap();
println!("name is {}", name);

code

  • string to base58
use rskit::base::code::base58_encode;
let s = "hello world";
let res = base58_encode(s.as_bytes()).unwrap();
println!("res is: {}", res);
  • base58 to string
use rskit::base::code::{base58_encode, base58_decode};
let s = "hello world";
let ss = base58_encode(s.as_bytes()).unwrap();
let res = base58_decode(&ss).unwrap();
println!("res is: {}", String::from_utf8(res).unwrap());
  • string to base64
use rskit::base::code::base64_encode;
let s = "hello world";
let res = base64_encode(s.as_bytes()).unwrap();
println!("res is: {}", res);
  • base64 to string
use rskit::base::code::{base64_encode, base64_decode};
let s = "hello world";
let ss = base64_encode(s.as_bytes()).unwrap();
let res = base64_decode(&ss).unwrap();
println!("res is: {}", String::from_utf8(res).unwrap());

lib

  • fast_log
use std::{thread, time::Duration};
rskit::Log::new().init_file().unwrap();
rskit::log::info!("init log ...");
thread::sleep(Duration::from_secs(1));
  • config
let mut config = rskit::Configs::<Settings>::new();
let settings = config.init(None).unwrap();
println!("version: {}", settings.app.version);

serde

  • to_json
use rskit::sd::*;
let aoo = Aoo {
    name: String::from("ok"),
    age: 18,
    date: Local::now(),
};

match to_json(aoo) {
    Ok(s) => {
        println!("aoo is {}", s);
    }
    Err(e) => println!("to_json error: {}", e),
}
  • from_json
use rskit::sd::*;
let s = r#"{"name":"ok","age":18, "date": "2024-08-15 11:00:16.100"}"#;
match from_json::<'_, Aoo>(s) {
    Ok(aoo) => {
        println!("aoo is: {:?}", aoo);
    }
    Err(e) => println!("from_json error: {}", e),
}

hash

  • hash_256
use rskit::base::code::hash_256;
let res = hash_256("hello world");
println!("hash 256 is {}", res);
  • hash_512
use rskit::base::code::hash_512;
let res = hash_512("hello world");
println!("hash 512 is {}", res);

crypto

  • generate aes key
use rskit::crypto::aes::*;
gen_rand_string(None);
  • aes cbc 128
use rskit::crypto::aes::*;
let key = gen_rand_string(Some(16));
let key = key.as_bytes();
let des = encrypt_aes_cbc_128(key, b"hello world");
let res = decrypt_aes_cbc_128(key, des.as_slice());
println!(
    "aes cbc 128 decrypt is {:?}",
    String::from_utf8(res).unwrap()
);
  • aes cbc 256
use rskit::crypto::aes::*;
let key = gen_rand_string(Some(32));
let key = key.as_bytes();
let des = encrypt_aes_cbc_256(key, b"hello world");
let res = decrypt_aes_cbc_256(key, des.as_slice());
println!(
    "aes cbc 256 decrypt is {:?}",
    String::from_utf8(res).unwrap()
);
  • aes gcm 128
use rskit::crypto::aes::*;
let key = aes_gcm_key_128();
let nonce = aes_gcm_nonce_128();
let des = encrypt_aes_gcm_128(&key, &nonce, b"hello world");
let res = decrypt_aes_gcm_128(&key, &nonce, des.as_slice());
println!(
    "aes gcm 128 decrypt is {:?}",
    String::from_utf8(res).unwrap()
);
  • aes gcm 256
use rskit::crypto::aes::*;
let key = aes_gcm_key_256();
let nonce = aes_gcm_nonce_256();
let des = encrypt_aes_gcm_256(&key, &nonce, b"hello world");
let res = decrypt_aes_gcm_256(&key, &nonce, des.as_slice());
println!(
    "aes gcm 256 decrypt is {:?}",
    String::from_utf8(res).unwrap()
);
  • generate rsa pair
use rskit::crypto::rsa::*;
let res = generate_rsa_pair(None);
println!("key pair: {:?}", res);
  • rsa
use rskit::crypto::rsa::*;
let (pri_key, pub_key) = generate_rsa_pair(None);
let src = "hello world";
let enc = encrypt_rsa_base(&pub_key, src.as_bytes()).unwrap();
let res = decrypt_rsa_base(&pri_key, &enc).unwrap();
println!("src: {}", src);
println!("res: {}", String::from_utf8(res).unwrap());
MIT License Copyright (c) 2020 itooling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/itooling/rskit.git
git@gitee.com:itooling/rskit.git
itooling
rskit
rskit
main

搜索帮助