Protectorion encryption source code

 

Protectorion encrypts all data using the industry leading Advanced Encryption Standard (AES) 256 bit. AES 256 bit is also used by many governments and enterprises around the world.

 

public bool Encrypt(string sourcepath, string targetfile, string keyphrase)

{

Rfc2898DeriveBytes keygenerator = null;

using(FileStream ifstream = new FileStream(sourcepath, FileMode.Open, FileAccess.Read, FileShare.Read, BUFFERSIZE, false))

{

  using(FileStream ofstream = new FileStream(targetfile, FileMode.Create, FileAccess.Write, FileShare.Write, BUFFERSIZE, false))

  {

   // Set up the encryption classes

   keygenerator = new Rfc2898DeriveBytes(keyphrase, Salt, 1234);

   using(Rijndael encryptiondevice = Rijndael.Create())

   {

    encryptiondevice.Key = keygenerator.GetBytes(32);

    encryptiondevice.IV = IV;

    using(CryptoStream encryptstream = new CryptoStream(ofstream, encryptiondevice.CreateEncryptor(), CryptoStreamMode.Write))

    {

     // copy the source file to the target file enctypting it on the fly.

     byte[] buffer = new byte[BUFFERSIZE];

     int bytesread = ifstream.Read(buffer, 0, BUFFERSIZE);

     RunProgress += bytesread;

     while(bytesread > 0)

     {

      encryptstream.Write(buffer, 0, bytesread);

      bytesread = ifstream.Read(buffer, 0, BUFFERSIZE);

     }

     encryptstream.FlushFinalBlock();

     encryptstream.Close();

     ifstream.Flush(); ifstream.Close();

     keygenerator.Reset();

     return true;

    }

   }

  }

}

}