Skip to content

Commit

Permalink
Docs and Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbate19 committed Sep 6, 2023
1 parent 2f04118 commit 823c1e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/_docs/user-guide/eldritch.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,16 @@ sys.shell("ls /nofile")
### crypto.aes_encrypt_file
`crypto.aes_encrypt_file(src: str, dst: str, key: str) -> None`

The <b>crypto.aes_encrypt_file</b> method encrypts and decrypts the given src file, encrypts it using the given key, and writes it to disk at the dst location.
The <b>crypto.aes_encrypt_file</b> method encrypts the given src file, encrypts it using the given key and writes it to disk at the dst location.

This uses the AES CTR algorithm, and the key parameter will be used for the key and IV.
Key must be 16 Bytes (Characters)

### crypto.aes_decrypt_file
`crypto.aes_decrypt_file(src: str, dst: str, key: str) -> None`

The <b>crypto.aes_decrypt_file</b> method decrypts the given src file using the given key and writes it to disk at the dst location.

Key must be 16 Bytes (Characters)

### crypto.hash_file
`crypto.hash_file(file: str, algo: str) -> str`
Expand Down
10 changes: 10 additions & 0 deletions implants/lib/eldritch/src/crypto/aes_decrypt_file_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ mod tests {
assert!(decrypt_file("/I/Dont/Exist".to_string(), test_path.to_str().unwrap().to_owned(), "TESTINGPASSWORD!".to_string()).is_err());
Ok(())
}

#[test]
fn test_decrypt_bad_size() -> Result<()> {
let tmp_dir = TempDir::new()?;
let test_path = tmp_dir.path().join("test.txt");
let mut tmp_file = File::create(test_path.clone())?;
tmp_file.write(&[0u8; 15])?;
assert!(decrypt_file(test_path.to_str().unwrap().to_owned(), test_path.to_str().unwrap().to_owned(), "TESTINGPASSWORD!".to_string()).is_err());
Ok(())
}
}

0 comments on commit 823c1e2

Please sign in to comment.