コード例 #1
0
        public virtual async Task ExportItem(T value)
        {
            var ext    = $"{value.ConnectionType.ToString().ToLower()}{ExportFileExtensionSuffix}";
            var dialog = new SaveFileDialog
            {
                FilterIndex     = 1,
                Filter          = $"Connection info files (*.{ext})|*.{ext}",
                Title           = Resources.ConnectionInfo_Dialog_Export_Title,
                FileName        = $"{value.Name}.{ext}",
                OverwritePrompt = true,
            };

            if (dialog.ShowDialog() != true)
            {
                return;                              // Break if cancel
            }
            try
            {
                // Password input
                var initialPassword = Membership.GeneratePassword(12, 0);
                var(result, password) = await MainWindow.ShowPasswordInputDialog(
                    Resources.ConnectionInfo_Dialog_Export_PasswordInput_Message,
                    Resources.ConnectionInfo_Dialog_Export_Title,
                    initialPassword
                    );

                if (result == false)
                {
                    return;                  // Break if cancel
                }
                var filename = dialog.FileName;
                MyLogger.Log($"Exporting \"{value.Name}\" to \"{filename}\"...");

                var data      = value.Serialize();
                var key       = AesUtil.GenerateKeyFromPassword(password);
                var encrypted = AesUtil.Encrypt(data, key);
                var encoded   = Convert.ToBase64String(encrypted);
                File.WriteAllText(filename, encoded);

                MyLogger.Log($"Exported \"{value.Name}\" to \"{filename}\".");

                // Set password to clipboard
                Clipboard.SetText(password);
                await MainWindow.ShowMessageDialog(
                    string.Format(Resources.ConnectionInfo_Dialog_Export_Exported, filename),
                    Resources.ConnectionInfo_Dialog_Export_Title);

                // Open saved dir
                System.Diagnostics.Process.Start(Path.GetDirectoryName(filename));
            }
            catch (Exception ex)
            {
                MyLogger.Log($"Failed to export.", ex);
                await MainWindow.ShowMessageDialog(
                    string.Format(Resources.ConnectionInfo_Dialog_Export_Error, ex.Message),
                    Resources.ConnectionInfo_Dialog_Export_Title);
            }
        }
コード例 #2
0
ファイル: zero.xaml.cs プロジェクト: Avalon305/AI_Recovery
        //获得aes加密insert
        private void Button_Click_14(object sender, RoutedEventArgs e)
        {
            string mac = System.Text.Encoding.Default.GetString(AesUtil.Encrypt(System.Text.Encoding.Default.GetBytes("00:16:3E:0C:B2:B3"), ProtocolConstant.USB_DOG_PASSWORD));
            //string mac = AesUtil.AesEncrypt("E4:02:9B:55:8E:30", "E4:02:9B:55:8E:30");
            SetterService setterService = new SetterService();

            entity.Setter setter = new entity.Setter();
            setter.Set_Unique_Id = mac;
            setterService.InsertSetter(setter);

            //MessageBox.Show(mac);
        }
コード例 #3
0
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            byte[] content = Encoding.ASCII.GetBytes("abcdrfghijklmnopqrstuvwxyz12345678901");

            byte[] jiamihou = AesUtil.Encrypt(content, ProtocolConstant.USB_DOG_PASSWORD);

            var jiemihou = AesUtil.Decrypt(jiamihou, ProtocolConstant.USB_DOG_PASSWORD);

            var str = Encoding.ASCII.GetString(jiemihou);

            MessageBoxX.Info(str);
        }
コード例 #4
0
        private async void SendButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(UserNameTextBox.Text) || string.IsNullOrEmpty(MessageTextBox.Text))
            {
                return;
            }

            var encryptedMessage = AesUtil.Encrypt(MessageTextBox.Text, ((int)_key).ToString());

            await _connection.InvokeAsync("SendMessage", UserNameTextBox.Text, encryptedMessage);

            MessageTextBox.Text = string.Empty;
        }
コード例 #5
0
ファイル: zero.xaml.cs プロジェクト: Avalon305/AI_Recovery
        /// <summary>
        /// 测试激活
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_16(object sender, RoutedEventArgs e)
        {
            SetterDAO setterDAO = new SetterDAO();

            //获取mac地址
            StringBuilder stringBuilder = new StringBuilder();
            //string strMac = CommUtil.GetMacAddress();
            // List<string> Macs = CommUtil.GetMacByWMI();
            List <string> Macs = CommUtil.GetMacByIPConfig();

            foreach (string mac in Macs)
            {
                string prefix = "物理地址. . . . . . . . . . . . . : ";
                string Mac    = mac.Substring(prefix.Length - 1);
                stringBuilder.Append(Mac);
            }
            //Console.WriteLine("==================="+stringBuilder.ToString());
            //MessageBox.Show("===================" + stringBuilder.ToString());
            entity.Setter setter = new entity.Setter();
            //mac地址先变为byte[]再aes加密
            byte[] byteMac = Encoding.GetEncoding("GBK").GetBytes(stringBuilder.ToString());
            byte[] AesMac  = AesUtil.Encrypt(byteMac, ProtocolConstant.USB_DOG_PASSWORD);
            //存入数据库
            //setter.Set_Unique_Id = Encoding.GetEncoding("GBK").GetString(AesMac);
            setter.Set_Unique_Id = ProtocolUtil.BytesToString(AesMac);

            /*AES解密
             * byte[] a = ProtocolUtil.StringToBcd(setter.Set_Unique_Id);
             * byte[] b = AesUtil.Decrypt(a, ProtocolConstant.USB_DOG_PASSWORD);
             * Console.WriteLine(Encoding.GetEncoding("GBK").GetString(b));*/
            //默认照片路径,激活时获取(路径中不要有汉字)
            string basePath = System.AppDomain.CurrentDomain.BaseDirectory;
            string path     = ConfigurationManager.AppSettings["PicPath"];

            setter.Set_PhotoLocation = basePath + path;
            setter.Set_Language      = 1;
            setter.Pk_Set_Id         = 1;
            //设置版本号
            setter.Set_Version = CommUtil.GetCurrentVersion();
            if (!Directory.Exists(@setter.Set_PhotoLocation))
            {
                Directory.CreateDirectory(@setter.Set_PhotoLocation);//不存在就创建目录
            }

            /*if (Directory.Exists(@setter.Set_PhotoLocation)) {  //存在就删除
             *  Directory.Delete(@setter.Set_PhotoLocation, true);
             *  Directory.CreateDirectory(@setter.Set_PhotoLocation);
             * }*/
            setterDAO.InsertOneMacAdress(setter);
        }
コード例 #6
0
        /// <summary>
        /// 组装U盘参数
        /// </summary>
        /// <param name="result"></param>
        /// <param name="cmd"></param>
        /// <param name="data"></param>
        public void PackData(ref byte[] result, byte[] cmd, byte[] data)
        {
            byte[] encryptData = AesUtil.Encrypt(data, ProtocolConstant.USB_DOG_PASSWORD);
            int    len         = encryptData.Length;

            result    = new byte[len + 6];
            result[0] = 0xAA;                                    //1.帧首
            result[1] = cmd[0];                                  //2.命令
            string hex = len.ToString("x4");                     //int转成16进制字符串

            result[2] = Convert.ToByte(hex.Substring(0, 2), 16); //16进制字符串(数字化)转字节 3.长度
            result[3] = Convert.ToByte(hex.Substring(2, 2), 16);

            for (int i = 0; i < encryptData.Length; i++)
            {
                result[4 + i] = encryptData[i];
            }
            //4.异或校检
            byte xor = ProtocolUtil.XorByByte(result, 1, 3 + len);

            result[result.Length - 2] = xor;
            //5.协议尾
            result[result.Length - 1] = 0xCC;
        }
コード例 #7
0
        private void EncryptBtn_Click(object sender, RoutedEventArgs e)
        {
            var encryptUtil = new AesUtil(Password.Text, Salt.Text);

            EncryptedText.Text = encryptUtil.Encrypt(PlainText.Text);
        }
コード例 #8
0
 public void EncryptTest()
 {
     Assert.Equal("OiGFDP47HdtJxgDbs/KvUQ==", AesUtil.Encrypt(STR_EN, SECRET));
     Assert.Equal("eyrfpEEEqwdXvtHoRUF7XgeN49Ug+v7LxMDf/4An0bU=", AesUtil.Encrypt(STR_CH, SECRET));
 }
コード例 #9
0
 public ActionResult <string> EncryptAes(string str, string userId)
 {
     return(Ok(AesUtil.Encrypt(str, Guid.Parse(userId))));
 }
コード例 #10
0
        private void Btn_Activate(object sender, RoutedEventArgs e)
        {
            //InputNonPublicInformationPassword
            InputNonPublicInformationPassword passwordInput = new InputNonPublicInformationPassword
            {
                Owner                 = Window.GetWindow(this),
                ShowActivated         = true,
                ShowInTaskbar         = false,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            passwordInput.ShowDialog();
            if (ProtocolConstant.USB_SUCCESS == 0) //u盘成功读取 破解状态为0
            {                                      //获取mac地址
                StringBuilder stringBuilder = new StringBuilder();
                //string strMac = CommUtil.GetMacAddress();
                // List<string> Macs = CommUtil.GetMacByWMI();
                List <string> Macs = CommUtil.GetMacByIPConfig();
                foreach (string mac in Macs)
                {
                    string prefix = "物理地址. . . . . . . . . . . . . : ";
                    string Mac    = mac.Substring(prefix.Length - 1);
                    stringBuilder.Append(Mac);
                }
                //Console.WriteLine("==================="+stringBuilder.ToString());
                //MessageBox.Show("===================" + stringBuilder.ToString());
                entity.Setter setter = new entity.Setter();
                //mac地址先变为byte[]再aes加密
                byte[] byteMac = Encoding.GetEncoding("GBK").GetBytes(stringBuilder.ToString());
                byte[] AesMac  = AesUtil.Encrypt(byteMac, ProtocolConstant.USB_DOG_PASSWORD);
                //存入数据库
                //setter.Set_Unique_Id = Encoding.GetEncoding("GBK").GetString(AesMac);
                setter.Set_Unique_Id = ProtocolUtil.BytesToString(AesMac);

                /*AES解密
                 * byte[] a = ProtocolUtil.StringToBcd(setter.Set_Unique_Id);
                 * byte[] b = AesUtil.Decrypt(a, ProtocolConstant.USB_DOG_PASSWORD);
                 * Console.WriteLine(Encoding.GetEncoding("GBK").GetString(b));*/
                //默认照片路径,激活时获取(路径中不要有汉字)
                string basePath = System.AppDomain.CurrentDomain.BaseDirectory;
                string path     = ConfigurationManager.AppSettings["PicPath"];
                setter.Set_PhotoLocation = basePath + path;
                setter.Set_Language      = 1;
                //默认备份路径,激活时获取
                setter.Back_Up      = basePath + @"BackUp\";
                setter.Set_Language = 1;
                //设置版本号
                setter.Set_Version = CommUtil.GetCurrentVersion();
                if (!Directory.Exists(@setter.Set_PhotoLocation))
                {
                    Directory.CreateDirectory(@setter.Set_PhotoLocation);//不存在就创建目录
                }

                /*if (Directory.Exists(@setter.Set_PhotoLocation)) {  //存在就删除
                 *  Directory.Delete(@setter.Set_PhotoLocation, true);
                 *  Directory.CreateDirectory(@setter.Set_PhotoLocation);
                 * }*/
                SetterDAO.InsertOneMacAdress(setter);
                //注释的部分为添加多个mac地址
                // List<entity.Setter> ListMac = CommUtil.GetMacByWMI();
                // SetterDAO.InsertMacAdress(ListMac);



                Status.Content = LanguageUtils.GetCurrentLanuageStrByKey("SettingsView.Activated");
                Color color = Color.FromArgb(255, 2, 200, 5);
                Status.Foreground     = new SolidColorBrush(color);
                BtnActivite.IsEnabled = false;
            }
            else
            {
                MessageBoxX.Error(LanguageUtils.ConvertLanguage("激活失败", "Activation fails"));
            }
        }