السلام عليكم
هذا الكود يعمل على تشقير ملف او stream بخوازمية RijndaelManaged
هل يمكن ان استخدم خوارزمي اخرى من ضمن بيئة .NET تقوم بعملية تشفير stream
مثلا مثل خوارزمية RSA ؟؟
وما هي هذه الخوارزمية RijndaelManaged ؟؟؟
private void button8_Click(object sender, System.EventArgs e)
{
byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x
12, 0x13, 0x14, 0x15, 0x16};
byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12,
0x13, 0x14, 0x15, 0x16};
EncryptData(@"c:\enc.exe", @"c:\enc2.exe", Key, IV);
//________________________________________________________________
//will encrypt (enc.exe) into new file (enc2.exe)
//________________________________________________________________
}
private static void EncryptData(String inName, String outName, byte[] rijnKey, byte[] rijnIV)
{
//Create the file streams to handle the input and output files.
FileStream fin = new FileStream(inName, FileMode.OpenOrCreate, FileAccess.Read);
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.
Write);
fout.SetLength(0);
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen = 0; //This is the total number of bytes written.
long totlen = fin.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); //Creates the default
implementation, which is RijndaelManaged.
CryptoStream encStream = new CryptoStream(fout, rijn.CreateEncryptor(rijnKey,
rijnIV), CryptoStreamMode.Write);
//Read from the input file, then encrypt and write to the output file.
while(rdlen < totlen)
{
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
}
encStream.Close();
fout.Close();
fin.Close();
}
private void button9_Click(object sender, System.EventArgs e)
{
byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x
12, 0x13, 0x14, 0x15, 0x16};
byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12,
0x13, 0x14, 0x15, 0x16};
DecryptData(@"c:\enc3.exe", @"c:\enc2.exe", Key, IV);
//________________________________________________________________
//will decncrypt (enc2.exe) into new file (enc3.exe)
//you can compare between enc.exe and enc3.exe and show it!!!!!!!
//________________________________________________________________
}
private static void DecryptData(String inName, String outName, byte[] rijnKey, byte[] rijnIV)
{
//Create the file streams to handle the input and output files.
FileStream fin = new FileStream(inName, FileMode.OpenOrCreate, FileAccess.Write);
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Read
);
fin.SetLength(0);
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen = 0; //This is the total number of bytes written.
long totlen = fout.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); //Creates the default
implementation, which is RijndaelManaged.
CryptoStream encStream = new CryptoStream(fin, rijn.CreateDecryptor(rijnKey,
rijnIV), CryptoStreamMode.Write);
//Read from the input file, then encrypt and write to the output file.
while(rdlen < totlen)
{
len = fout.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
}
encStream.Close();
fout.Close();
fin.Close();
}:rolleyes:

