static void Main(string[] args) { byte[] plainText = new byte[] {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; byte[] cipherText = new byte[16]; byte[] decipheredText = new byte[16]; byte[] keyBytes = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}; Aes a = new Aes(Aes.KeySize.Bits128, keyBytes); Console.WriteLine("\nAdvanced Encryption Standard Demo in .NET"); Console.WriteLine("\nThe plaintext is: "); DisplayAsBytes(plainText); Console.WriteLine("\nUsing a " + Aes.KeySize.Bits192.ToString() + "-key of: "); DisplayAsBytes(keyBytes); a.Cipher(plainText, cipherText); Console.WriteLine("\nThe resulting ciphertext is: "); DisplayAsBytes(cipherText); a.InvCipher(cipherText, decipheredText); Console.WriteLine("\nAfter deciphering the ciphertext, the result is: "); DisplayAsBytes(decipheredText); Console.WriteLine("\nDone"); Console.ReadLine(); }
private void saveSettings() { try { dcSQL.Server = txtServerName.Text; dcSQL.Database = cbDatabaseName.Text; if (rbNTSecurity.Checked) { dcSQL.SecurityType = DatabaseConfiguration.WINDOWS_NT_SECURITY; } else if (rbSQLSecurity.Checked) { dcSQL.UserId = txtUserId.Text; dcSQL.Password = txtPassword.Text; dcSQL.SecurityType = DatabaseConfiguration.SQLSERVER_SECURITY; } dcSQL.TestConnection(); if (dcSQL.Connected) { keysize = Aes.KeySize.Bits128; byte[] plainText = new byte[16]; byte[] cipherText = new byte[16]; plainText = Encoding.Unicode.GetBytes(txtPassword.Text.PadRight(8, ' ')); AesLib.Aes a = new Aes(keysize, new byte[16]); a.Cipher(plainText, cipherText); string passasc = Encoding.Unicode.GetString(cipherText); if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "settings.dat")) File.Delete(AppDomain.CurrentDomain.BaseDirectory + "settings.dat"); FileInfo inf = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "settings.dat"); StreamWriter writer = inf.CreateText(); writer.WriteLine(txtServerName.Text); writer.WriteLine(txtUserId.Text); writer.WriteLine(passasc); writer.WriteLine(cbDatabaseName.Text); ExMessageBox.Show("Đã lưu", "Thông tin", ExMessageBox.CYButtons.OK, ExMessageBox.CYIcon.Information); writer.Close(); }//if else { ExMessageBox.Show("Kết nối không thành công. Vui lòng kiểm tra lại các thông số kết nối!", "Thông tin", ExMessageBox.CYButtons.OK, ExMessageBox.CYIcon.Error); } } catch(AppException ex) { String strMessage =ex.Message; } }