using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
class Program
{
static void Main(string[] args)
{
Program program = new Program();
program.skrij(args);
program.odkrij(args);
}
string niz, besedilo, password, ime, konec, ime2, test, geslo1, geslo2, geslo;
int d, dol, a, b, dolg, dolg2, e, pak;
public void skrij(string[] args)
{
niz = besedilo;
besedilo = niz;
password = "igor";
ime = "kresnik";
byte[] output;
int bytesRead;
niz = besedilo;
konec = niz.Substring(niz.LastIndexOf('.') + 1);
Console.WriteLine("'{0}'", konec);
ime2 = niz;
string[] z = ime2.Split('.');
if (z[1] == konec)
{
z[1] = ".temp";
test = z[0] + z[1];
}
using (FileStream inFile = new FileStream(besedilo, FileMode.Open))
using (FileStream outFile = new FileStream(test, FileMode.Create))
{
password = geslo1;
ime = geslo2;
geslo = password + ime;
byte[] passwordBytes = Encoding.UTF8.GetBytes(geslo);
using (Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(passwordBytes, salt, iterations))
{
byte[] keyBytes = derivedBytes.GetBytes(keySize / 8);
byte[] ivBytes = derivedBytes.GetBytes(16);
using (Aes aesAlg = Aes.Create())
{
aesAlg.KeySize = keySize;
aesAlg.Key = keyBytes;
aesAlg.IV = ivBytes;
using (CryptoStream csEncrypt = new CryptoStream(outFile, aesAlg.CreateEncryptor(), CryptoStreamMode.Write))
{
byte[] inputBuffer = new byte[dol];
while ((bytesRead = inFile.Read(inputBuffer, 0, inputBuffer.Length)) > 0)
{
// the bottom line reports error cs1061
output = csEncrypt.TransformFinalBlock(inputBuffer, 0, bytesRead);
outFile.Write(output, 0, output.Length);
}
}
}
}
}
File.Delete(besedilo);
}
public void odkrij(string[] args)
{
byte[] output;
int read;
niz = besedilo;
konec = niz.Substring(niz.LastIndexOf('.') + 1);
Console.WriteLine("'{0}'", konec);
ime2 = niz;
string[] z = ime2.Split('.');
if (z[1] == konec)
{
z[1] = ".temp";
test = z[0] + z[1];
}
string password = geslo1;
string ime = geslo2;
byte[] salt = Encoding.UTF8.GetBytes(ime);
geslo = password + ime;
using (FileStream fis = new FileStream(niz, FileMode.Open))
using (FileStream fos = new FileStream(test, FileMode.Create))
{
password = geslo1;
ime = geslo2;
geslo = password + ime;
byte[] passwordBytes = Encoding.UTF8.GetBytes(geslo);
using (Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(passwordBytes, salt, iterations))
{
byte[] keyBytes = derivedBytes.GetBytes(keySize / 8);
byte[] ivBytes = derivedBytes.GetBytes(16);
using (Aes aesAlg = Aes.Create())
{
aesAlg.KeySize = keySize;
aesAlg.Key = keyBytes;
aesAlg.IV = ivBytes;
using (CryptoStream csDecrypt = new CryptoStream(fos, aesAlg.CreateDecryptor(), CryptoStreamMode.Write))
{
byte[] inputBuffer = new byte[dol];
while ((read = fis.Read(inputBuffer, 0, inputBuffer.Length)) > 0)
{
// the bottom line reports error cs1061
output = csDecrypt.TransformFinalBlock(inputBuffer, 0, read);
fos.Write(output, 0, output.Length);
}
}
}
}
}
File.Delete(niz);
}
byte[] salt = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
int iterations = 65536;
int keySize = 256;
}