
using System.IO;
using System.Security.Cryptography;
namespace gukwon_ransomeware_client
{
public class Decryptor
{
private RijndaelManaged aes;
public Decryptor(byte[] Key, byte[] IV)
{
aes = new RijndaelManaged();
aes.KeySize = 256;
aes.BlockSize = 128;
aes.Padding = PaddingMode.PKCS7;
aes.Mode = CipherMode.CBC;
aes.Key = Key;
aes.IV = IV;
}
public void DecryptFiles(string[] pathes)
{
int count;
int blockSizeBytes = aes.BlockSize / 8;
byte[] data = new byte[blockSizeBytes];
FileStream inFs;
FileStream outFs;
CryptoStream cryptoStream;
for (int i = 0; i < pathes.Length; i++)
{
if (File.Exists(pathes[i] + ".encrypted"))
{
inFs = new FileStream(pathes[i] + ".encrypted", FileMode.Open);
outFs = new FileStream(pathes[i], FileMode.Create);
cryptoStream = new CryptoStream(outFs, aes.CreateDecryptor(), CryptoStreamMode.Write);
do
{
count = inFs.Read(data, 0, blockSizeBytes);
cryptoStream.Write(data, 0, count);
}
while (count > 0);
inFs.Close();
cryptoStream.FlushFinalBlock();
cryptoStream.Close();
outFs.Close();
File.Delete(pathes[i] + ".encrypted");
}
}
}
}
}
- 파일 경로 리스트를 인자로 받아 해당 파일 경로의 파일을 복호화하는 역할을 하는 메서드를 가진 클래스이다.