Skip to content

Commit

Permalink
use sha256 as function encrypt key
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Aug 24, 2024
1 parent 1e3d057 commit 28b869c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
78 changes: 78 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ anyhow = "1.0.86"
clap = { version = "4.5.3", features = ["derive"] }
memmap2 = "0.9.4"
rust-crypto = "0.2.36"
sha2 = "0.10.8"
thiserror = "1.0.63"
14 changes: 4 additions & 10 deletions src/obfus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,10 @@ impl Obfuscator {
}

pub fn encrypt_function_name(&mut self, function: &str, key: &str) -> crate::error::Result<()> {
let mut key_bytes = [0; 32];
if key.len() > 32 {
return Err(crate::error::Error::InvalidOption(
"key length must be less than 32",
));
}
for (i, byte) in key.bytes().enumerate() {
key_bytes[i] = byte;
}
let encryptor = crypto::aessafe::AesSafe256Encryptor::new(&key_bytes);
use sha2::digest::Digest as _;

let hash = sha2::Sha256::digest(key.as_bytes());
let encryptor = crypto::aessafe::AesSafe256Encryptor::new(&hash);

let tmp_file = std::fs::OpenOptions::new()
.read(true)
Expand Down

0 comments on commit 28b869c

Please sign in to comment.