Protectorion verschlüsselt alle Daten und Passwörter mit dem als sicher anerkannten Industriestandard AES 256 bit, der weltweit von Regierungsbehörden und großen Unternehmen zum Schutz vertraulicher Daten eingesetzt wird.
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;
}
}
}
}
}