diff --git a/src/EncFi.py b/src/EncFi.py deleted file mode 100644 index 249e8ec..0000000 --- a/src/EncFi.py +++ /dev/null @@ -1,83 +0,0 @@ -""" -For Encryption and Decryption of Files -Anfu 2021 -*This file is a part of Anfu -""" -from cryptography.fernet import Fernet -import os -from rich import print -import time -import getpass -from tkinter import * - -def CheckOs(): - if os.name =='nt': - return "Windows" - return "Linux" -class FileEncryption: - def EncryptFile(self,path): - try: - self.path = path - FileName = os.path.basename(self.path) - #Generating an Fernet Encryption Key - Encryption_key = Fernet.generate_key() - with open(self.path,"rb")as ReadFile: - FileContent = ReadFile.read() - ReadFile.close() - #Using the Encryption Key - fernet = Fernet(Encryption_key) - #Encrypting the FileContent - Encrypted_Content = fernet.encrypt(FileContent) - #Writing the Encrypted Content into Orignal File - with open(self.path,"wb") as WriteFile: - WriteFile.write(Encrypted_Content) - WriteFile.close() - #print Message - #check os and make dirs and save keys - if CheckOs() == 'Windows': - if os.path.exists(f'C:\\Users\\{getpass.getuser()}\\Desktop\\ANFU_KEYS') is False: - os.mkdir(f"C:\\Users\\{getpass.getuser()}\\Desktop\\ANFU_KEYS") - with open(f"C:\\Users\\{getpass.getuser()}\\Desktop\\ANFU_KEYS\\{FileName}.FILE.anky","wb") as WriteKey: - WriteKey.write(Encryption_key) - WriteKey.close() - else: - if os.path.exists(f"/home/{getpass.getuser()}/Desktop/ANFU_KEYS") is False: - os.mkdir(f"/home/{getpass.getuser()}/Desktop/ANFU_KEYS") - with open(f"/home/{getpass.getuser()}/Desktop/ANFU_KEYS/{FileName}.FILE.anky","wb") as WriteKey: - WriteKey.write(Encryption_key) - WriteKey.close() - print("[green]Encryption Key File Available at /Desktop/ANFU_KEYS.Keep the Encryption Key safe or you [red]won't[/red] be able to Decrypt Files again[/green]\n") - except: - print("An Error Occured.Possible Reasons:\n1:Permission Error\n2:File was a Directory\nInvalid Encoding") - def DecryptFile(self,keyfile,Encrypted_File): - try: - self.keyfile = keyfile - self.Encrypted_File = Encrypted_File - #Openining File and Reading Key - with open(self.keyfile,"rb") as ReadKey: - Key = ReadKey.read() - ReadKey.close() - #Using key file - fernet = Fernet(Key) - #Opening Encrypted file and Reading it - with open(self.Encrypted_File,"rb") as encrypted_file: - EncryptedContent = encrypted_file.read() - encrypted_file.close() - #Decrypting the content - Decrypted = fernet.decrypt(EncryptedContent) - #Opening the file and writing the Decrypted content again - with open(self.Encrypted_File,"wb") as WriteDecrypted: - WriteDecrypted.write(Decrypted) - WriteDecrypted.close() - except: - ErrWindow = Tk() - ErrWindow.title("ERROR") - Label(ErrWindow,text="An Error Occured While Decrypting the File").pack() - Label(ErrWindow,text="Possible Reasons might be:").pack() - Label(ErrWindow,text="1:File wasn't Encrypted,or was corrupted").pack() - Label(ErrWindow,text="2:Invalid Decryption Key").pack() - Label(ErrWindow,text="3:File Permission Error").pack() - ErrWindow.mainloop() - print("[red]An Error occured.Possible Reasons:\n1:Invalid Key\n2:File wasn't Encrypted\n3:File Permission Error\n4:File was a Directory[/red]") - - diff --git a/src/EncFo.py b/src/EncFo.py deleted file mode 100644 index 2676aec..0000000 --- a/src/EncFo.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -For Encryption and Decryption of Folders -Anfu 2021 -""" -import shutil -from cryptography.fernet import Fernet -from zipfile import ZipFile -import os -from rich import print -import time -from tkinter import * -import getpass -#Check Os -def CheckOs(): - if os.name =='nt': - return "Windows" - return "Linux" - -class FolderEncryption: - def EncryptFoler(self,path): - try: - #Extracting root dir from path(dir where file is present) - _root_dir = os.path.dirname(path) - #Extracting Basename from path - _File_basename = os.path.basename(path) - #Adding Folder to zip so we can encrypt the zip - shutil.make_archive(_File_basename,'zip',path) - #Generating the Encryption Key - Encryption_key = Fernet.generate_key() - #For using the Key - fernet = Fernet(Encryption_key) - #Openinig the zip file to encrypt it - with open(f"{_File_basename}.zip","rb") as ReadContent: - Content = ReadContent.read() - ReadContent.close() - #Encrypting the file content - EncryptedContent = fernet.encrypt(Content) - #Writing Encrypted content to File - with open(f"{_File_basename}.zip","wb") as WriteEncrypted: - WriteEncrypted.write(EncryptedContent) - WriteEncrypted.close() - #check os and make dirs and save keys - if CheckOs() == 'Windows': - if os.path.exists(f'C:\\Users\\{getpass.getuser()}\\Desktop\\ANFU_KEYS') is False: - os.mkdir(f"C:\\Users\\{getpass.getuser()}\\Desktop\\ANFU_KEYS") - with open(f"C:\\Users\\{getpass.getuser()}\\Desktop\\ANFU_KEYS\\{_File_basename}.DIR.anky","wb") as WriteKey: - WriteKey.write(Encryption_key) - WriteKey.close() - else: - if os.path.exists(f"/home/{getpass.getuser()}/Desktop/ANFU_KEYS") is False: - os.mkdir(f"/home/{getpass.getuser()}/Desktop/ANFU_KEYS") - with open(f"/home/{getpass.getuser()}/Desktop/ANFU_KEYS/{_File_basename}.DIR.anky","wb") as WriteKey: - WriteKey.write(Encryption_key) - WriteKey.close() - #Removing the directory and moving the zip to that dir - shutil.rmtree(path) - shutil.move(f"{_File_basename}.zip",_root_dir) - except: - print("[red]An Error Occured.Possible Reasons:\n1:Permission Error[/red]") - def DecryptFolder(self,keyfile,Encrypted_Dir): - try: - #Extracting root dir where zip file is present - _root_dir = os.path.dirname(Encrypted_Dir) - #Extracting Directory name from Encrypted Zip file - _zip_file_name = os.path.basename(Encrypted_Dir) - _dir_name = _zip_file_name.split(".")[0] - with open(keyfile,"rb") as KeyFile: - Key = KeyFile.read() - KeyFile.close() - #Using the Encryption Key - fernet = Fernet(Key) - #Opening the Encrypted File and Read it - with open(Encrypted_Dir,"rb") as Encrypted_Content: - Encrypted = Encrypted_Content.read() - Encrypted_Content.close() - #Decrypting the content - Decrypted = fernet.decrypt(Encrypted) - #Opening the file and writing the decrypted content - with open(Encrypted_Dir,"wb") as WriteDecrypted: - WriteDecrypted.write(Decrypted) - WriteDecrypted.close() - #Extracting the zip file to directory and deleting the zip - with ZipFile(Encrypted_Dir,"r") as ZipObj: - if CheckOs() == "Windows": - ZipObj.extractall(f"{_root_dir}\\{_dir_name}") - else: - ZipObj.extractall(f"{_root_dir}/{_dir_name}") - os.remove(Encrypted_Dir) - except: - ErrWindow = Tk() - ErrWindow.title("ERROR") - Label(ErrWindow,text="An Error Occured While Decrypting the Directory").pack() - Label(ErrWindow,text="Possible Reasons might be:").pack() - Label(ErrWindow,text="1:Folder wasn't Encrypted,or was corrupted").pack() - Label(ErrWindow,text="2:Invalid Decryption Key").pack() - Label(ErrWindow,text="3:Permission Error").pack() - ErrWindow.mainloop() - print("[red]An Error Occured.Possible Reasons:\n1:Permission Error\n2:Invalid Encryption Key[/red]") - diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index 7f74625..0000000 --- a/src/__init__.py +++ /dev/null @@ -1 +0,0 @@ -#Empty __init__.py to recognize this folder as a module