Skip to content

Commit

Permalink
Added encode and decode functionalities, resolved most typescript err…
Browse files Browse the repository at this point in the history
…ors, added icons, fixed encrypt and decrypt text moduleremoved unwanted stuff and cleaned up
  • Loading branch information
man2k committed Aug 30, 2023
1 parent dbe72f5 commit 0006498
Show file tree
Hide file tree
Showing 32 changed files with 357 additions and 369 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"react-type-animation": "^3.1.0"
"react-type-animation": "^3.1.0",
"zwsp-steg": "^1.0.1"
},
"devDependencies": {
"@tauri-apps/cli": "^1.4.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

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

File renamed without changes
File renamed without changes
Binary file modified src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
Binary file modified src-tauri/icons/icon.ico
Binary file not shown.
Binary file modified src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src-tauri/src/app-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 43 additions & 71 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// use aes::cipher::generic_array::functional;

use aes::Aes128;
use aes::Aes192;
use aes::Aes256;
Expand All @@ -9,34 +9,23 @@ use chrono::Utc;

use block_modes::block_padding::Pkcs7;
use block_modes::{BlockMode, Cbc};
use dirs;
use hex::encode;
use rand::Rng;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::process::Command;
use steganography::decoder::*;
use steganography::encoder::*;
use steganography::util::*;
// use tauri::api::file;

use dirs;
use std::process::Command;

type Aes128Cbc = Cbc<Aes128, Pkcs7>;
type Aes256Cbc = Cbc<Aes256, Pkcs7>;
type Aes192Cbc = Cbc<Aes192, Pkcs7>;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
// #[tauri::command]
// fn greet(name: &str) -> String {
// format!("Hello, {}! You've been greeted from Rust!", name)
// }

// fn type_of<T>(_: T) -> &'static str {
// type_name::<T>()
// }

fn passargon(password: String, size: usize) -> Result<([u8; 16], Vec<u8>), &'static str> {
let mut salt: [u8; 16] = [0u8; 16];
let mut rng = rand::thread_rng();
Expand All @@ -46,6 +35,7 @@ fn passargon(password: String, size: usize) -> Result<([u8; 16], Vec<u8>), &'sta
Argon2::default().hash_password_into(password.as_bytes(), &salt, &mut output_key_material);
Ok((salt, output_key_material))
}

fn keygenargon(password: String, size: usize, salt: [u8; 16]) -> Result<Vec<u8>, &'static str> {
let mut output_key_material = vec![0u8; size]; // Can be any desired size
let _ =
Expand Down Expand Up @@ -75,7 +65,6 @@ async fn steganograph(
// .expect("Error Saving Encrypted File");

// let message = "This is a steganography demo!".to_string();
//Convert our string to bytes
if file_path == "" {
println!("No file");
let plaintext = data.as_bytes();
Expand All @@ -91,16 +80,9 @@ async fn steganograph(
let payload = &finalchipher;

let destination_image = file_as_dynamic_image(img_path);
//Create an encoder
let enc = Encoder::new(payload, destination_image);
//Encode our message into the alpha channel of the image
let result = enc.encode_alpha();
//Save the new image
// save_image_buffer(
// result,
// r"M:\pROGRAMMING fILES\DedSec\passdomtauri\passdomNative\src\assets\hidden_message.png"
// .to_string(),
// );

save_image_buffer(result, finalpath.to_str().unwrap().to_string());
return finalpath.to_str().unwrap().to_string();
} else if file_path != "" {
Expand Down Expand Up @@ -143,8 +125,8 @@ async fn steganograph(
async fn desteganograph(
img_path: String,
password: String,
fileortext: bool,
finalpath: String,
_fileortext: bool,
_finalpath: String,
) -> String {
// if !fileortext {
let encoded_image = file_as_image_buffer(img_path);
Expand All @@ -157,10 +139,10 @@ async fn desteganograph(
// DECRYPTION
let plaintext2 = clean_buffer;
let (content, ivv) = plaintext2.split_at(plaintext2.len() - 16);
let mut buf = content.to_vec();
let mut buffer = content.to_vec();
let fkey = keygenargon(password, 32, ivv.try_into().unwrap()).unwrap();
let cipher = Aes256Cbc::new_from_slices(&fkey, &ivv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let s = std::str::from_utf8(&decrypted_ciphertext).unwrap();
println!("Dec : {}", s);
return s.to_string();
Expand All @@ -176,10 +158,10 @@ async fn desteganograph(
// // DECRYPTION
// let plaintext2 = clean_buffer;
// let (content, ivv) = plaintext2.split_at(plaintext2.len() - 16);
// let mut buf = content.to_vec();
// let mut buffer = content.to_vec();
// let fkey = keygenargon(password, 32, ivv.try_into().unwrap()).unwrap();
// let cipher = Aes256Cbc::new_from_slices(&fkey, &ivv).unwrap();
// let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
// let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
// // let downloads = dirs::download_dir().expect("Could not find downloads directory");
// println!("{}", finalpath);
// let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
Expand Down Expand Up @@ -231,10 +213,6 @@ async fn encryptfile(
let (iv, key) = passargon(password, algo / 8).unwrap();
println!("iv : {:?} \nkey : {:?}", iv, key);
if algo == 128 {
// let iv = rand::thread_rng().gen::<[u8; 16]>();
// let key = rand::thread_rng().gen::<[u8; 16]>();
// println!("Key: {}", encode(&key));
// println!("IV: {}", encode(&iv));
let cipher = Aes128Cbc::new_from_slices(&key, &iv).unwrap();
let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
let finalchipher = [ciphertext, &iv].concat();
Expand All @@ -243,12 +221,7 @@ async fn encryptfile(
let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
fil.write_all(&finalchipher)
.expect("Error Saving Encrypted File");
// Ok(encode(key).into())
} else if algo == 192 {
// let iv = rand::thread_rng().gen::<[u8; 16]>();
// let key = rand::thread_rng().gen::<[u8; 24]>();
// println!("Key: {}", encode(key));
// println!("IV: {}", encode(iv));
let cipher = Aes192Cbc::new_from_slices(&key, &iv).unwrap();
let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
let finalchipher = [ciphertext, &iv].concat();
Expand All @@ -257,12 +230,7 @@ async fn encryptfile(
let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
fil.write_all(&finalchipher)
.expect("Error Saving Encrypted File");
// Ok(encode(key).into())
} else if algo == 256 {
// let iv = rand::thread_rng().gen::<[u8; 16]>();
// let key = rand::thread_rng().gen::<[u8; 32]>();
// println!("Key: {}", encode(key));
// println!("IV: {}", encode(iv));
let cipher = Aes256Cbc::new_from_slices(&key, &iv).unwrap();
let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
let finalchipher = [ciphertext, &iv].concat();
Expand All @@ -271,7 +239,6 @@ async fn encryptfile(
let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
fil.write_all(&finalchipher)
.expect("Error Saving Encrypted File");
// Ok(encode(key).into())
} else {
return Ok("failed".to_string());
}
Expand All @@ -285,46 +252,49 @@ async fn encryptfile(
}

#[tauri::command]
async fn encrypttext(text_str: String, algo: usize) -> (String, String) {
async fn encrypttext(text_str: String, password: String, algo: usize) -> Result<String, ()> {
println!("encrypt text working...");
let plaintext = text_str.as_bytes();
let pos = plaintext.len();
let mut buffer: Vec<u8> = vec![0u8; pos + 100];
buffer[..pos].copy_from_slice(&plaintext);

let (iv, key) = passargon(password, algo / 8).unwrap();
println!("iv : {:?} \nkey : {:?}", iv, key);
if algo == 128 {
let key = rand::thread_rng().gen::<[u8; 16]>();
let iv = rand::thread_rng().gen::<[u8; 16]>();
println!("key : {}", encode(&key));
println!("iv : {}", encode(&iv));
// let key = rand::thread_rng().gen::<[u8; 16]>();
// let iv = rand::thread_rng().gen::<[u8; 16]>();
// println!("key : {}", encode(&key));
// println!("iv : {}", encode(&iv));
let cipher = Aes128Cbc::new_from_slices(&key, &iv).unwrap();

let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
let finalchipher = [ciphertext, &iv].concat();
println!("finalchipher : {:?}", finalchipher);
(encode(finalchipher).into(), encode(key).into())
Ok(encode(finalchipher).into())
} else if algo == 192 {
let key = rand::thread_rng().gen::<[u8; 24]>();
let iv = rand::thread_rng().gen::<[u8; 16]>();
println!("key : {}", encode(&key));
println!("iv : {}", encode(&iv));
// let key = rand::thread_rng().gen::<[u8; 24]>();
// let iv = rand::thread_rng().gen::<[u8; 16]>();
// println!("key : {}", encode(&key));
// println!("iv : {}", encode(&iv));
let cipher = Aes192Cbc::new_from_slices(&key, &iv).unwrap();
let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
let finalchipher = [ciphertext, &iv].concat();
println!("finalchipher : {:?}", finalchipher);
(encode(finalchipher).into(), encode(key).into())
Ok(encode(finalchipher).into())
} else if algo == 256 {
let key = rand::thread_rng().gen::<[u8; 32]>();
let iv = rand::thread_rng().gen::<[u8; 16]>();
println!("key : {}", encode(&key));
println!("iv : {}", encode(&iv));
// let key = rand::thread_rng().gen::<[u8; 32]>();
// let iv = rand::thread_rng().gen::<[u8; 16]>();
// println!("key : {}", encode(&key));
// println!("iv : {}", encode(&iv));
let cipher = Aes256Cbc::new_from_slices(&key, &iv).unwrap();
let ciphertext = cipher.encrypt(&mut buffer, pos).unwrap();
let finalchipher = [ciphertext, &iv].concat();
println!("finalchipher : {:?}", finalchipher);

(encode(finalchipher).into(), encode(key).into())
Ok(encode(finalchipher).into())
} else {
("failed".into(), "failed".into())
Ok("failed".into())
}
}

Expand All @@ -349,14 +319,14 @@ async fn decryptfile(

// let fkey = hex::decode(key).expect("Decoding failed");
let fkey = keygenargon(password, algo / 8, iv.try_into().unwrap()).unwrap();
let mut buf = content.to_vec();
let mut buffer = content.to_vec();

println!("IV: {}", encode(&iv));
println!("Key: {}", encode(&fkey));

if algo == 128 {
let cipher = Aes128Cbc::new_from_slices(&fkey, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let downloads = dirs::download_dir().expect("Could not find downloads directory");
let finalpath = downloads.join(file_name);
let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
Expand All @@ -365,7 +335,7 @@ async fn decryptfile(
Ok("This worked!".into())
} else if algo == 192 {
let cipher = Aes192Cbc::new_from_slices(&fkey, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let downloads = dirs::download_dir().expect("Could not find downloads directory");
let finalpath = downloads.join(file_name);
let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
Expand All @@ -374,7 +344,7 @@ async fn decryptfile(
Ok("This worked!".into())
} else if algo == 256 {
let cipher = Aes256Cbc::new_from_slices(&fkey, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let downloads = dirs::download_dir().expect("Could not find downloads directory");
let finalpath = downloads.join(file_name);
let mut fil = File::create(finalpath).expect("Error Creating Encrypted File");
Expand All @@ -387,30 +357,32 @@ async fn decryptfile(
}

#[tauri::command]
async fn decrypttext(text: String, key: String, algo: usize) -> Result<String, ()> {
async fn decrypttext(text: String, password: String, algo: usize) -> Result<String, ()> {
// let plaintext = text.as_bytes();
let plaintext = hex::decode(text).expect("Decoding failed");
println!("plain : {:?}", plaintext);
let (content, iv) = plaintext.split_at(plaintext.len() - 16);
println!("content : {:?}", content);
let fkey = hex::decode(key).expect("Decoding failed");
let mut buf = content.to_vec();
// let fkey = hex::decode(key).expect("Decoding failed");
let fkey = keygenargon(password, algo / 8, iv.try_into().unwrap()).unwrap();

let mut buffer = content.to_vec();

println!("key : {}", encode(&fkey));
println!("iv : {}", encode(&iv));
if algo == 128 {
let cipher = Aes128Cbc::new_from_slices(&fkey, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let s = std::str::from_utf8(&decrypted_ciphertext).unwrap();
Ok(s.to_string())
} else if algo == 192 {
let cipher = Aes192Cbc::new_from_slices(&fkey, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let s = std::str::from_utf8(&decrypted_ciphertext).unwrap();
Ok(s.to_string())
} else if algo == 256 {
let cipher = Aes256Cbc::new_from_slices(&fkey, &iv).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buf).unwrap();
let decrypted_ciphertext = cipher.decrypt(&mut buffer).unwrap();
let s = std::str::from_utf8(&decrypted_ciphertext).unwrap();
Ok(s.to_string())
} else {
Expand Down
Binary file removed src/assets/hidden_message.png
Binary file not shown.
Loading

0 comments on commit 0006498

Please sign in to comment.