by Darkness Yetkili Premium • 2025-12-29 14:57
🎯 Amaç
Hassas dosyaların ele geçirilse bile okunamamasını sağlamak.
Bu yaklaşım; veri sızıntısı, ransomware etkisini azaltma ve Zero‑Trust mimarisinin temelidir.
📌 Ne yapar?
Dosyayı AES‑256 ile şifreler
Anahtar olmadan dosya tamamen anlamsız hale gelir
Veri çalınsa bile gizlilik korunur
using System;
using System.IO;
using System.Security.Cryptography;
class FileEncryptionTool
{
static void Main()
{
Console.Write("Şifrelenecek dosya yolu: ");
string inputFile = Console.ReadLine();
Console.Write("Çıkış dosyası yolu: ");
string outputFile = Console.ReadLine();
Console.Write("Parola girin: ");
string password = Console.ReadLine();
EncryptFile(inputFile, outputFile, password);
Console.WriteLine("Dosya başarıyla şifrelendi.");
}
static void EncryptFile(string inputFile, string outputFile, string password)
{
byte[] salt = new byte[16];
RandomNumberGenerator.Fill(salt);
using var key = new Rfc2898DeriveBytes(password, salt, 100000);
using var aes = Aes.Create();
aes.KeySize = 256;
aes.Key = key.GetBytes(32);
aes.GenerateIV();
using var fsOut = new FileStream(outputFile, FileMode.Create);
fsOut.Write(salt, 0, salt.Length);
fsOut.Write(aes.IV, 0, aes.IV.Length);
using var cryptoStream = new CryptoStream(fsOut, aes.CreateEncryptor(), CryptoStreamMode.Write);
using var fsIn = new FileStream(inputFile, FileMode.Open);
fsIn.CopyTo(cryptoStream);
}
}