الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تشفير stream بخوارزميات .NET?

مغلق
بدأه m_lahlouh في 26 أكتوبر 2005 · 5 رد · 795 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

هذا الكود يعمل على تشقير ملف او 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:

عندما تولد يا ابن آدم يؤذن في اذنك من غير صلاة...

وعندما تموت.... يصلى عليك من غير آذان....

فكأن حياتك في الدنيا ليست سوى... الوقت الذي تمضيه بين الأذان والصلاة...

فلا تقضيه بما لاينفع

Mohammad Lahlouh

mohammadlahlouh.blogspot.com

Make money from your Website or Blog with BidVertiser

#2

السلام عليكم ورحمة الله وبركاته

لا علاقة للخواريزمية بالبيئة

يمكن إستخدام الخواريزميات الأخرى

d4baa0.gif
#3

السلام عليكم

اذا اردت معلومات عن التشفير و خوارزمياته بصفه عامه فمن اين احصل عليها.... و جزاكم الله خيراً

#4

وعليكم السلام ورحمة الله وبركاته.

لو نظرت في Security.Cryptography Namespace ستجد الاجابه.

نعم الدوت نت بها أيضا كلاسات لعمل تشفير Asymmetric , فتجد بها RSA و DSA وستجد الكلاسات ( الـ Providers ) الخاصه بهما.

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

#5

اشكرك اخي معتز شمس , كنت انوي شرحها في سلسلة الدروس الخاصة ببرمجة الشبكات , اذا كانت لديك اية معلومات اضافية حولها ارجوا منك تزويدنا بها .. واشكرك مرة اخرى

تم تعديل هذه المشاركة بواسطة fmo_82 في 27 أكتوبر 2005 في 10:35

#6

للأسف أنا ليس لدى معلومات كبيره بها فأنا لم أقرء في هذا الموضوع سوى كتاب واحد فقط حتى الآن ( وأعتقد أنه لا يوجد كتب متخصصه غيره تتحدث عن التشفير في الدوت نت ) وسأحاول أن أضعه ان شاء الله في المكتبه هذه الأيام.

المشكله أنه حتى يصبح الشخص ملم وخبير بها ينبغي عليه القراءه عنها كثيرا بصفه عامه وعن تاريخها الحافل والممتلئ بالمعادلات الرياضيه :)

ولكن بالطبع اذا أردنا القيام ببرنامج صغير يقوم بتشفير الملفات بـبـ Password مثلا وهذه الأشياء فالدوت نت تسهل الأمر كثيرا.

اقرأ مقدمه عنها كتبها الأخ SOLO في منتدى VB ::

/index.php?showtopic=78514

#Read

http://MoutazShams.blogspot.com

projects003.gif

أعتذر عن التغيب هذه الأيام نظرا للانشغال المريب

هذا الموضوع مغلق.

مواضيع مشابهة