PDA

View Full Version : یه روش یا یه ocx جهت کد کردن اطلاعات



mah_2008
یک شنبه 20 خرداد 1386, 18:37 عصر
من می خوام اطلاعات داخل یکی از جدول هام رو کد کنم
یه کد یابهتر از اون یه ocx می خوام که بتونم اطلاعاتم را کد شده به داخل جدول بفرستم
وبعد هم بتونم اطلاعات را دی کد کنم و داخل فرم هام نشون بدم.

ARA
یک شنبه 20 خرداد 1386, 19:05 عصر
سلام چیز خاصی نمیخواهد
چون همه چیزش تو .net هستش یک مثال از msdn هستش این ناگوریتم Rijndael هستش




using System;using System.Security.Cryptography;using System.Text;using System.IO;class RijndaelSample{ static void Main() { try { // Create a new Rijndael object to generate a key // and initialization vector (IV). Rijndael RijndaelAlg = Rijndael.Create(); // Create a string to encrypt. string sData = "Here is some data to encrypt."; string FileName = "CText.txt"; // Encrypt text to a file using the file name, key, and IV. EncryptTextToFile(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV); // Decrypt the text from a file using the file name, key, and IV. string Final = DecryptTextFromFile(FileName, RijndaelAlg.Key, RijndaelAlg.IV); // Display the decrypted string to the console. Console.WriteLine(Final); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); } public static void EncryptTextToFile(String Data, String FileName, byte[] Key, byte[] IV) { try { // Create or open the specified file. FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate); // Create a new Rijndael object. Rijndael RijndaelAlg = Rijndael.Create(); // Create a CryptoStream using the FileStream // and the passed key and initialization vector (IV). CryptoStream cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(Key, IV), CryptoStreamMode.Write); // Create a StreamWriter using the CryptoStream. StreamWriter sWriter = new StreamWriter(cStream); try { // Write the data to the stream // to encrypt it. sWriter.WriteLine(Data); } catch (Exception e) { Console.WriteLine("An error occurred: {0}", e.Message); } finally { // Close the streams and // close the file. sWriter.Close(); cStream.Close(); fStream.Close(); } } catch (CryptographicException e) { Console.WriteLine("A Cryptographic error occurred: {0}", e.Message); } catch (UnauthorizedAccessException e) { Console.WriteLine("A file error occurred: {0}", e.Message); } } public static string DecryptTextFromFile(String FileName, byte[] Key, byte[] IV) { try { // Create or open the specified file. FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate); // Create a new Rijndael object. Rijndael RijndaelAlg = Rijndael.Create(); // Create a CryptoStream using the FileStream // and the passed key and initialization vector (IV). CryptoStream cStream = new CryptoStream(fStream, RijndaelAlg.CreateDecryptor(Key, IV), CryptoStreamMode.Read); // Create a StreamReader using the CryptoStream. StreamReader sReader = new StreamReader(cStream); string val = null; try { // Read the data from the stream // to decrypt it. val = sReader.ReadLine(); } catch (Exception e) { Console.WriteLine("An error occurred: {0}", e.Message); } finally { // Close the streams and // close the file. sReader.Close(); cStream.Close(); fStream.Close(); } // Return the string. return val; } catch (CryptographicException e) { Console.WriteLine("A Cryptographic error occurred: {0}", e.Message); return null; } catch (UnauthorizedAccessException e) { Console.WriteLine("A file error occurred: {0}", e.Message); return null; } }}

:چشمک:

mah_2008
دوشنبه 21 خرداد 1386, 13:31 عصر
از جوابی که دادین ممنونم
اما اگه می تونستین یه ocxبرای این کار برام بفرستین خیلی خوب می شد
چون من عجله دارم وباید هرچه سریعتر این کار را انجام بدم
لطف می کنین

ARA
دوشنبه 21 خرداد 1386, 17:55 عصر
ما به همدیگه ماهی نمدیم ماهیگیری یاد میدیم