增加一个预处理password的方法
This commit is contained in:
parent
5109226cda
commit
5150df13ed
@ -5,8 +5,9 @@
|
||||
//
|
||||
|
||||
use rustwallet::{
|
||||
free_cwallet, generate_sec_key, get_address, get_public_key, hex_deflate, hex_inflate,
|
||||
new_wallet, rencrypt, sign, sign_for_tran, wallet_decrypt, wallet_encrypt, CWallet,
|
||||
free_cwallet, generate_sec_key, get_address, get_public_key, hash_pass_svr, hex_deflate,
|
||||
hex_inflate, keccak256_hash, new_wallet, rencrypt, sign, sign_for_tran, wallet_decrypt,
|
||||
wallet_encrypt, CWallet,
|
||||
};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::os::raw::c_char;
|
||||
@ -132,12 +133,19 @@ fn main() {
|
||||
|
||||
let str_decode = hex_inflate(str_encode);
|
||||
print_cchar!(str_decode);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn print_wallet(cwallet: &CWallet) {
|
||||
print_cchar!("msg=> ", cwallet.msg_key);
|
||||
print_cchar!("master key=> ", cwallet.master_key);
|
||||
print_cchar!("second key=> ", cwallet.second_key);
|
||||
print_cchar!("backup key=> ", cwallet.backup_key);
|
||||
let msg = "$argon2id$v=19$m=19456,t=2,p=1$adcr3ix1Mpcx2wWd/It8gw$VG1I+RrEQ5rbKlGiVDB2Lux50XTfxgaxLsvHG4SCtTI";
|
||||
let result = keccak256_hash(str_to_cchar!(msg));
|
||||
print_cchar!(result);
|
||||
let address2 = get_address(
|
||||
str_to_cchar!(msg_key),
|
||||
str_to_cchar!(key0),
|
||||
result,
|
||||
str_to_cchar!(key1),
|
||||
);
|
||||
print_cchar!(address2);
|
||||
let pass = "111111";
|
||||
let hash_pass = hash_pass_svr(str_to_cchar!(pass));
|
||||
print_cchar!(hash_pass);
|
||||
}
|
||||
}
|
||||
|
13
src/lib.rs
13
src/lib.rs
@ -244,6 +244,19 @@ pub unsafe extern "C" fn hex_inflate(content: *const c_char) -> *mut c_char {
|
||||
let msg_hex = base64_to_hex(&content_str);
|
||||
str_to_cchar!(msg_hex)
|
||||
}
|
||||
// hash pasword of email register
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn hash_pass_svr(content: *const c_char) -> *mut c_char {
|
||||
let content_str = cchar_to_str!(content);
|
||||
let msg_hex = utils::pass_utils::hash_pass_svr(&content_str);
|
||||
str_to_cchar!(msg_hex)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn keccak256_hash(content: *const c_char) -> *mut c_char {
|
||||
let content_str = cchar_to_str!(content);
|
||||
let msg_hex = utils::pass_utils::keccak256_hash(&content_str);
|
||||
str_to_cchar!(msg_hex)
|
||||
}
|
||||
|
||||
unsafe fn convert_to_cwallet(rwallet: Wallet) -> CWallet {
|
||||
let c_msgkey: *mut c_char = str_to_cchar!(rwallet.msg_key);
|
||||
|
@ -4,6 +4,7 @@ use argon2::{
|
||||
};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use std::str;
|
||||
use tiny_keccak::keccak256;
|
||||
|
||||
pub fn hash_password(pass: &str) -> String {
|
||||
let salt: SaltString = SaltString::generate(&mut OsRng);
|
||||
@ -34,3 +35,18 @@ pub fn verify_password(pass: &str, password_hash: &str) -> bool {
|
||||
.verify_password(password, &parsed_hash)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub fn keccak256_hash(str: &str) -> String {
|
||||
let data = str.as_bytes();
|
||||
let hasher = keccak256(data);
|
||||
hex::encode(&hasher)
|
||||
}
|
||||
|
||||
pub fn hash_pass_svr(str: &str) -> String {
|
||||
let message = str.as_bytes();
|
||||
let mut eth_message = format!("\x23cebg email regist:\n{}", message.len()).into_bytes();
|
||||
eth_message.extend_from_slice(message);
|
||||
|
||||
let hasher = keccak256(ð_message);
|
||||
hex::encode(&hasher)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user