private void DecryptFile() { var files = GetFiles("falsecrypt File (*.falsecrypt)|*.falsecrypt"); if (files == null || !files.Any()) { return; } var password = ShowPasswordEnter(); if (string.IsNullOrEmpty(password)) { return; } foreach (var file in files) { if (!File.Exists(file)) { continue; } try { EncryptionCryptoWrapper.DecryptFileWithPassword(new FileInfo(file), password); } catch (Exception e) { MessageBox.Show("Wrong password"); return; } } MessageBox.Show("Successfully decrypted"); }
private void EncryptFolder() { var folder = GetFolder(); if (string.IsNullOrEmpty(folder)) { return; } var password = ShowPasswordEnter(); if (string.IsNullOrEmpty(password)) { return; } var files = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories); // BUG 1: Key derivation should not be performed outside a foreach block that is using its return value. // Otherwise all operations in this loop have the same encryption key var keyData = WeakPasswordDerivation.DerivePassword(password); foreach (var file in files) { if (!File.Exists(file)) { continue; } EncryptionCryptoWrapper.EncryptFile(new FileInfo(file), keyData.Key, keyData.Salt); } MessageBox.Show("Successfully encrypted"); }
private void EncryptFile() { var files = GetFiles(); if (files == null || !files.Any()) { return; } var password = ShowPasswordEnter(); if (string.IsNullOrEmpty(password)) { return; } foreach (var file in files) { if (!File.Exists(file)) { continue; } EncryptionCryptoWrapper.EncryptFileWithPassword(new FileInfo(file), password); } MessageBox.Show("Successfully encrypted"); }
public void EncryptDecryptManual() { var message = "This is a secret Message"; var data = WeakPasswordDerivation.DerivePassword("password"); var cipherText = EncryptionCryptoWrapper.EncryptMessage(message, data.Key, Encoding.UTF8); var decryptedMessage = EncryptionCryptoWrapper.DecryptMessage(cipherText, data.Key, Encoding.UTF8); Assert.AreEqual(message, decryptedMessage); }
public void EncryptDecrypt() { var message = "This is a secret Message"; var cipherText = EncryptionCryptoWrapper.EncryptMessage(message, "password", Encoding.UTF8); var decryptedMessage = EncryptionCryptoWrapper.DecryptMessage(cipherText, "password", Encoding.UTF8); Assert.AreEqual(message, decryptedMessage); }
public void EncryptEncryptEqual() { var message = "This is a secret Message"; var password = "******"; var cipherText1 = EncryptionCryptoWrapper.EncryptMessage(message, password, Encoding.UTF8); var data = WeakPasswordDerivation.DerivePassword(password); var cipherText2 = EncryptionCryptoWrapper.EncryptMessage(message, data.Key, Encoding.UTF8); Assert.AreNotEqual(cipherText1, cipherText2); }
private void DecryptFolder() { var folder = GetFolder(); if (string.IsNullOrEmpty(folder)) { return; } var password = ShowPasswordEnter(); if (string.IsNullOrEmpty(password)) { return; } var files = Directory.GetFiles(folder, "*.falsecrypt", SearchOption.AllDirectories); // NOT A BUG for itself: The weakness of using the same key foreach file was caused by the encryption. // The decryption methods just matches contract the encryption sets var keyData = WeakPasswordDerivation.DerivePassword(password); foreach (var file in files) { if (!File.Exists(file)) { continue; } try { EncryptionCryptoWrapper.DecryptFile(new FileInfo(file), keyData.Key); } catch (Exception e) { MessageBox.Show("Wrong password"); return; } } MessageBox.Show("Successfully decrypted"); }