|
| 1 | +from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QFileDialog, QLabel, QMenu, QInputDialog, QFrame, QDialog, QAction |
| 2 | +from PyQt5.QtGui import QPixmap, QFont, QIcon |
| 3 | +from PyQt5.QtCore import Qt, QPoint, QUrl |
| 4 | +import os |
| 5 | +import base64 |
| 6 | +from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC |
| 7 | +from cryptography.hazmat.primitives.hashes import SHA256 |
| 8 | +from cryptography.fernet import Fernet |
| 9 | +import sys |
| 10 | + |
| 11 | +SALT = b'some_salt_value' # Şifre türetmek için sabit bir salt kullanılıyor. |
| 12 | + |
| 13 | +def get_logo_path(): |
| 14 | + # PyInstaller ile paketlendiğinde kullanılan yol |
| 15 | + if hasattr(sys, "_MEIPASS"): |
| 16 | + return os.path.join(sys._MEIPASS, "encolo.png") |
| 17 | + # Sabit bir sistem yolu |
| 18 | + elif os.path.exists("/usr/share/icons/hicolor/48x48/apps/encolo.png"): |
| 19 | + return "/usr/share/icons/hicolor/48x48/apps/encolo.png" |
| 20 | + home_dir = os.path.expanduser("/usr/share/icons/hicolor/48x48/apps/encolo.png") |
| 21 | + if os.path.exists(home_dir): |
| 22 | + return home_dir |
| 23 | + # Varsayılan olarak bulunduğu dizindeki encolo.png |
| 24 | + return "encolo.png" |
| 25 | + |
| 26 | +# Logo dosyasının yolu |
| 27 | +logo_path = get_logo_path() |
| 28 | + |
| 29 | +def derive_key(password: str) -> bytes: |
| 30 | + """Kullanıcı tarafından girilen şifreye göre bir anahtar türetir.""" |
| 31 | + kdf = PBKDF2HMAC( |
| 32 | + algorithm=SHA256(), |
| 33 | + length=32, |
| 34 | + salt=SALT, |
| 35 | + iterations=100000, |
| 36 | + ) |
| 37 | + return base64.urlsafe_b64encode(kdf.derive(password.encode())) |
| 38 | + |
| 39 | +class FileEncryptionApp(QMainWindow): |
| 40 | + def __init__(self): |
| 41 | + super().__init__() |
| 42 | + self.setWindowTitle("EnCo Dosya Kilitle/Çöz") |
| 43 | + self.setWindowIcon(QIcon(logo_path)) # Uygulama simgesi |
| 44 | + self.setGeometry(300, 200, 600, 400) |
| 45 | + self.setFixedSize(350, 450) |
| 46 | + self.key = None |
| 47 | + self.setStyleSheet("background-color: #2D2F31; color: #FFD24C;") |
| 48 | + self.setWindowOpacity(0.9) # %80 şeffaflık |
| 49 | + self.initUI() |
| 50 | + |
| 51 | + def initUI(self): |
| 52 | + self.central_widget = QWidget() |
| 53 | + self.setCentralWidget(self.central_widget) |
| 54 | + |
| 55 | + layout = QVBoxLayout() |
| 56 | + |
| 57 | + # Logo kısmı |
| 58 | + self.logo_label = QLabel(self) |
| 59 | + pixmap = QPixmap(logo_path) # Logoyu yüklüyoruz |
| 60 | + self.logo_label.setPixmap(pixmap) |
| 61 | + self.logo_label.setAlignment(Qt.AlignCenter) |
| 62 | + self.logo_label.setFixedHeight(100) # Logo yüksekliği |
| 63 | + |
| 64 | + self.label = QLabel("Dosya seçilmedi.") |
| 65 | + self.label.setFont(QFont("Arial", 12)) |
| 66 | + self.label.setAlignment(Qt.AlignCenter) |
| 67 | + |
| 68 | + button_layout = QVBoxLayout() |
| 69 | + self.encrypt_button = self.create_button("🔒 Dosyayı Kilitle", self.encrypt_file) |
| 70 | + self.decrypt_button = self.create_button("🔑 Dosyayı Çöz", self.decrypt_file) |
| 71 | + |
| 72 | + button_layout.addWidget(self.encrypt_button) |
| 73 | + button_layout.addWidget(self.decrypt_button) |
| 74 | + |
| 75 | + self.drop_frame = QFrame(self) |
| 76 | + self.drop_frame.setFrameShape(QFrame.StyledPanel) |
| 77 | + self.drop_frame.setStyleSheet("background-color: #FF967615; border-radius: 10px; height: 200px; margin: 20px;") |
| 78 | + self.drop_frame.setAcceptDrops(True) # Sürükle-bırak etkinleştirildi |
| 79 | + self.drop_frame.setObjectName("drop_frame") |
| 80 | + |
| 81 | + self.drop_label = QLabel("Dosyayı Sürükle Bırak", self.drop_frame) |
| 82 | + self.drop_label.setAlignment(Qt.AlignCenter) |
| 83 | + self.drop_label.setFont(QFont("Arial", 13)) |
| 84 | + self.drop_label.setStyleSheet("color: white;") |
| 85 | + |
| 86 | + self.click_to_select_label = QLabel("Dosya Seçmek İçin Tıklayınız.", self.drop_frame) |
| 87 | + self.click_to_select_label.setAlignment(Qt.AlignCenter) |
| 88 | + self.click_to_select_label.setFont(QFont("Arial", 9)) |
| 89 | + self.click_to_select_label.setStyleSheet("color: #A9A9A9;") |
| 90 | + |
| 91 | + self.drop_frame.setLayout(QVBoxLayout()) |
| 92 | + self.drop_frame.layout().addWidget(self.drop_label) |
| 93 | + self.drop_frame.layout().addWidget(self.click_to_select_label) |
| 94 | + self.drop_frame.layout().setContentsMargins(0, 0, 0, 0) |
| 95 | + |
| 96 | + layout.addWidget(self.logo_label) |
| 97 | + layout.addWidget(self.label) |
| 98 | + layout.addWidget(self.drop_frame) |
| 99 | + layout.addLayout(button_layout) |
| 100 | + |
| 101 | + self.central_widget.setLayout(layout) |
| 102 | + |
| 103 | + self.menu_button = QPushButton("⋮", self) |
| 104 | + self.menu_button.setStyleSheet(""" |
| 105 | + font-size: 20px; |
| 106 | + background-color: #2D2F31; |
| 107 | + color: #FFD24C; |
| 108 | + border: none; |
| 109 | + padding: 10px; |
| 110 | + """) |
| 111 | + self.menu_button.setFixedSize(40, 40) |
| 112 | + self.menu_button.clicked.connect(self.show_menu) |
| 113 | + self.menu_button.move(self.width() - 50, 20) |
| 114 | + |
| 115 | + self.file_path = None |
| 116 | + |
| 117 | + # Tıklama ile dosya seçme işlevi |
| 118 | + self.drop_frame.mousePressEvent = self.select_file_on_click |
| 119 | + |
| 120 | + def create_button(self, text: str, action): |
| 121 | + button = QPushButton(text) |
| 122 | + button.setStyleSheet(""" |
| 123 | + background-color: #FFA6841E; |
| 124 | + color: #2D2F31; |
| 125 | + font-size: 14px; |
| 126 | + border-radius: 10px; |
| 127 | + padding: 10px; |
| 128 | + margin: 10px; |
| 129 | + width: 200px; |
| 130 | + """) |
| 131 | + button.clicked.connect(action) |
| 132 | + button.setFixedHeight(60) |
| 133 | + return button |
| 134 | + |
| 135 | + def select_file(self): |
| 136 | + file_dialog = QFileDialog() |
| 137 | + file_path, _ = file_dialog.getOpenFileName(self, "Bir dosya seçin") |
| 138 | + if file_path: |
| 139 | + self.file_path = file_path |
| 140 | + self.label.setText(f"Seçilen Dosya: {os.path.basename(file_path)}") |
| 141 | + |
| 142 | + def select_file_on_click(self, event): |
| 143 | + self.select_file() |
| 144 | + |
| 145 | + def ask_password(self) -> str: |
| 146 | + password, ok = QInputDialog.getText(self, "Parola Girin", "Parola (4-64 karakter):") |
| 147 | + if ok and 4 <= len(password) <= 64: |
| 148 | + return password |
| 149 | + elif ok: |
| 150 | + self.label.setText("Parola uzunluğu 4-64 karakter arasında olmalıdır!") |
| 151 | + return None |
| 152 | + |
| 153 | + def encrypt_file(self): |
| 154 | + if not self.file_path: |
| 155 | + self.label.setText("Lütfen bir dosya seçin!") |
| 156 | + return |
| 157 | + |
| 158 | + password = self.ask_password() |
| 159 | + if not password: |
| 160 | + return |
| 161 | + |
| 162 | + self.key = derive_key(password) |
| 163 | + cipher = Fernet(self.key) |
| 164 | + |
| 165 | + try: |
| 166 | + with open(self.file_path, "rb") as file: |
| 167 | + data = file.read() |
| 168 | + |
| 169 | + encrypted_data = cipher.encrypt(data) |
| 170 | + encrypted_path = f"{self.file_path}.enco" |
| 171 | + |
| 172 | + with open(encrypted_path, "wb") as file: |
| 173 | + file.write(encrypted_data) |
| 174 | + |
| 175 | + os.remove(self.file_path) |
| 176 | + self.file_path = encrypted_path |
| 177 | + self.label.setText(f"Kilitleme tamamlandı: {os.path.basename(encrypted_path)}") |
| 178 | + |
| 179 | + except Exception as e: |
| 180 | + self.label.setText(f"Hata: {str(e)}") |
| 181 | + |
| 182 | + def decrypt_file(self): |
| 183 | + if not self.file_path or not self.file_path.endswith(".enco"): |
| 184 | + self.label.setText("Lütfen bir kilitlenmiş dosya seçin!") |
| 185 | + return |
| 186 | + |
| 187 | + password = self.ask_password() |
| 188 | + if not password: |
| 189 | + return |
| 190 | + |
| 191 | + self.key = derive_key(password) |
| 192 | + cipher = Fernet(self.key) |
| 193 | + |
| 194 | + try: |
| 195 | + with open(self.file_path, "rb") as file: |
| 196 | + encrypted_data = file.read() |
| 197 | + |
| 198 | + decrypted_data = cipher.decrypt(encrypted_data) |
| 199 | + original_path = self.file_path.rsplit(".enco", 1)[0] |
| 200 | + |
| 201 | + with open(original_path, "wb") as file: |
| 202 | + file.write(decrypted_data) |
| 203 | + |
| 204 | + os.remove(self.file_path) |
| 205 | + self.file_path = original_path |
| 206 | + self.label.setText(f"Çözme tamamlandı: {os.path.basename(original_path)}") |
| 207 | + |
| 208 | + except Exception as e: |
| 209 | + self.label.setText(f"Hata: {str(e)}") |
| 210 | + |
| 211 | + def dragEnterEvent(self, event): |
| 212 | + """Sürüklenen öğe, dosya ise kabul edilir.""" |
| 213 | + if event.mimeData().hasUrls(): |
| 214 | + event.acceptProposedAction() |
| 215 | + |
| 216 | + def dropEvent(self, event): |
| 217 | + """Sürükle bırak işlemi gerçekleştiğinde dosya yolu alır.""" |
| 218 | + file_path = event.mimeData().urls()[0].toLocalFile() |
| 219 | + self.file_path = file_path |
| 220 | + self.label.setText(f"Seçilen Dosya: {os.path.basename(file_path)}") |
| 221 | + |
| 222 | + def show_menu(self): |
| 223 | + menu = QMenu(self) |
| 224 | + about_action = QAction("Hakkında", self) |
| 225 | + about_action.triggered.connect(self.show_about) |
| 226 | + menu.addAction(about_action) |
| 227 | + menu.exec(self.menu_button.mapToGlobal(QPoint(0, 0))) |
| 228 | + |
| 229 | + def show_about(self): |
| 230 | + about_text = ( |
| 231 | + "\n\n" |
| 232 | + " EnCo Dosya Kilitleme Uygulaması\n\n" |
| 233 | + " Bu uygulama, dosyalarınızı kriptolayarak güvenli hale getirmenize olanak tanır.\n\n" |
| 234 | + " Geliştirici: ALG Yazılım Inc. | www.algyzilim.com | [email protected]\n\n" |
| 235 | + " Fatih ÖNDER (CekToR) | wwww.fatihonder.org.tr | [email protected]\n\n" |
| 236 | + " EnCo Tüm Hakları Saklıdır. 2024 ALG Software Inc\n\n" |
| 237 | + " \n\n" |
| 238 | + " ALG Yazılım Pardus'a Göç'ü Destekler." |
| 239 | + ) |
| 240 | + |
| 241 | + dialog = QDialog(self) |
| 242 | + dialog.setWindowTitle("Hakkında") |
| 243 | + dialog.resize(520, 250) |
| 244 | + label = QLabel(about_text, dialog) |
| 245 | + label.setWordWrap(True) |
| 246 | + label.setAlignment(Qt.AlignCenter) |
| 247 | + dialog.exec() |
| 248 | + |
| 249 | +if __name__ == "__main__": |
| 250 | + app = QApplication(sys.argv) |
| 251 | + window = FileEncryptionApp() |
| 252 | + window.show() |
| 253 | + sys.exit(app.exec()) |
0 commit comments