Пример #1
0
 private void btnBase64Bmp_ToBase64_Click(object sender, EventArgs e)
 {
     if (picBoxBase64Bmp.Image == null)
     {
         Base64BmpPicBmp();
     }
     try
     {
         rtxtBase64BmpStr.Text = $"data:image/png;base64,{Base64Helper.ImgToBase64(picBoxBase64Bmp.Image)}";
     }
     catch (Exception ex)
     {
         WinFormHelper.ShowError(ex);
     }
 }
Пример #2
0
        private void btn_Base64_Decode_Click(object sender, EventArgs e)
        {
            var codeText = rtxt_Base64_Orginal.Text;

            if (string.IsNullOrWhiteSpace(codeText))
            {
                WinFormHelper.ShowWarning("请输入要解码的文本!");
                return;
            }
            try
            {
                rtxt_Base64_Handled.Text = Base64Helper.UnBase64String(codeText);
            }
            catch (Exception ex)
            {
                WinFormHelper.ShowError(ex);
            }
        }
Пример #3
0
 private void btnBase64Bmp_ToBmp_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(rtxtBase64BmpStr.Text))
     {
         rtxtBase64BmpStr.Focus();
     }
     else
     {
         try
         {
             if (picBoxBase64Bmp.Image != null)
             {
                 picBoxBase64Bmp.Image.Dispose();
                 picBoxBase64Bmp.Image = null;
             }
             picBoxBase64Bmp.Image = Base64Helper.Base64ToImg(rtxtBase64BmpStr.Text.Replace("data:image/png;base64,", ""));
         }
         catch (Exception ex)
         {
             WinFormHelper.ShowError(ex);
         }
     }
 }
Пример #4
0
        private void btnImgCutterStart_Click(object sender, EventArgs e)
        {
            var selectedPath = txtImgCutterImgSelectPath.Text.Trim();
            var savePath     = txtImgCutterImgSavePath.Text.Trim();

            if (string.IsNullOrWhiteSpace(selectedPath))
            {
                WinFormHelper.ShowError("请选定需处理图片所在的文件夹!");
                return;
            }
            if (string.IsNullOrWhiteSpace(savePath))
            {
                WinFormHelper.ShowError("请选定处理后图片所保存的文件夹!");
                return;
            }
            if (ImgCutter_ImgPathList.Count <= 0)
            {
                BindImgCutterListView();
            }
            if (ImgCutter_ImgPathList.Count <= 0)
            {
                WinFormHelper.ShowError("指定的文件夹内无图片!");
                return;
            }



            if ((selectedPath == savePath && MessageBox.Show(this, "保存图片的路径与来源一致,图片将被覆盖!请确认继续", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) || savePath != selectedPath)
            {
                var cutWidthStr  = txtImgCutterImgWidth.Text.Trim();
                var cutHeightStr = txtImgCutterImgHeight.Text.Trim();

                int cutWidth = 0, cutHeight = 0;

                if (rbImgCutterSolidBoth.Checked)
                {
                    if (string.IsNullOrEmpty(cutHeightStr) || string.IsNullOrEmpty(cutWidthStr))
                    {
                        WinFormHelper.ShowError("请指定图片的宽高!");
                        return;
                    }
                    cutHeight = Convert.ToInt32(cutHeightStr);
                    cutWidth  = Convert.ToInt32(cutWidthStr);
                }
                else if (rbImgCutterSolidWidth.Checked)
                {
                    if (string.IsNullOrEmpty(cutWidthStr))
                    {
                        WinFormHelper.ShowError("请指定图片的宽度!");
                        return;
                    }

                    cutHeight = 0;
                    cutWidth  = Convert.ToInt32(cutWidthStr);
                }
                else if (rbImgCutterSolidHeight.Checked)
                {
                    if (string.IsNullOrEmpty(cutHeightStr))
                    {
                        WinFormHelper.ShowError("请指定图片的高度!");
                        return;
                    }
                    cutHeight = Convert.ToInt32(cutHeightStr);
                    cutWidth  = 0;
                }
                else
                {
                    return;
                }

                if (ckbImgCutterImgWatermark.Checked && string.IsNullOrEmpty(ImgCutter_WatermarkTextOrImgPath))
                {
                    WinFormHelper.ShowError("请指定水印图片!");
                    txtImgCutterImgWatermarkPath.Focus();
                    return;
                }
                else if (ckbImgCutterTxtWatermark.Checked && string.IsNullOrEmpty(ImgCutter_WatermarkTextOrImgPath))
                {
                    WinFormHelper.ShowError("请输入水印文字!");
                    txtImgCutterTxtWatermark.Focus();
                    return;
                }
                else
                {
                    imgCutter = new ImgCutter(ImgCutter_ImgPathList, cutWidth, cutHeight, ImgCutter_RootPath, savePath, ImgCutter_IsUseWaterMark, ImgCutter_WatermarkTypeEnum, ImgCutter_WatermarkPosition, ImgCutter_WatermarkTextOrImgPath);
                }

                if (imgCutter != null)
                {
                    imgCutter.TaskProgress.ProgressChanged += ImgCutter_StatusProgressEvent;
                    imgCutter.CutProgress.ProgressChanged  += ImgCutter_ProgressEvent;
                    imgCutter.Action();
                }
            }
        }
Пример #5
0
        private void btnSymmetricEncryption_Dencrypt_Click(object sender, EventArgs e)
        {
            var orginal = rtxtSymmetricEncryptionOrginal.Text;

            if (string.IsNullOrWhiteSpace(orginal))
            {
                rtxtSymmetricEncryptionOrginal.Focus();
                return;
            }
            var key = txtSymmetricEncryptionKey.Text;

            if (string.IsNullOrWhiteSpace(key))
            {
                txtSymmetricEncryptionKey.Focus();
                return;
            }
            try
            {
                switch (Convert.ToInt32(cmbSymmetricEncryptionEncryptMethod.SelectedValue))
                {
                case 1:     // AES128
                    rtxtSymmetricEncryptionHandled.Text = SecurityHelper.AES_128.Decrypt(orginal, key);
                    break;

                case 2:     // AES256
                    if (key.Length != 32)
                    {
                        rtxtSymmetricEncryptionHandled.Text = "密钥必须为32位!";
                        break;
                    }
                    rtxtSymmetricEncryptionHandled.Text = SecurityHelper.AES_256.Decrypt(orginal, key);
                    break;

                case 3:     // DES
                    if (key.Length != 8)
                    {
                        rtxtSymmetricEncryptionHandled.Text = "密钥必须为8位!";
                        break;
                    }
                    rtxtSymmetricEncryptionHandled.Text = SecurityHelper.DES.Decrypt(orginal, key);
                    break;

                case 4:     // RC4
                    using (SecurityHelper.RC4Crypt crypter = new SecurityHelper.RC4Crypt(key))
                    {
                        rtxtSymmetricEncryptionHandled.Text = crypter.Decrypt(orginal);
                    }
                    break;

                case 5:     // Rabbit
                    break;

                case 6:     // TripleDES
                    rtxtSymmetricEncryptionHandled.Text = SecurityHelper.TripleDES.Decrypt(orginal, key);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                WinFormHelper.ShowError(ex);
            }
        }
Пример #6
0
        private void btnPortScanerStart_Click(object sender, EventArgs e)
        {
            ipStateList.Clear();
            ipStateBindingList.Clear();
            rtxtPortScanerStatus.Clear();
            lstbPortScanerStatus.DataSource = ipStateBindingList;
            ipStateBindingList.Add("IP地址              " + "    端口       " + "  端口状态 " + "             服务");
            btnPortScanerStop.Enabled  = true;
            btnPortScanerStart.Enabled = false;



            if (cbPortScanerSingleIp.Checked)
            {
                txtPortScanerIpEnd.Text = txtPortScanerIpStart.Text;
            }
            if (cbPortScanerSinglePort.Checked)
            {
                txtPortScanerPortEnd.Text = txtPortScanerPortStart.Text;
            }

            if (IpHelper.IsIp(txtPortScanerIpEnd.Text) && IpHelper.IsIp(txtPortScanerIpStart.Text))//匹配正确IP
            {
                try
                {
                    if (IpHelper.IpToInt64(txtPortScanerIpStart.Text) <= IpHelper.IpToInt64(txtPortScanerIpEnd.Text))
                    {
                        if (string.IsNullOrEmpty(txtPortScanerPortStart.Text) || string.IsNullOrEmpty(txtPortScanerPortEnd.Text))
                        {
                            WinFormHelper.ShowError("请输入端口号!");
                        }
                        else
                        {
                            ipStart   = IpHelper.IpToInt64(txtPortScanerIpStart.Text);
                            ipEnd     = IpHelper.IpToInt64(txtPortScanerIpEnd.Text);
                            portStart = Int32.Parse(txtPortScanerPortStart.Text);
                            portEnd   = Int32.Parse(txtPortScanerPortEnd.Text);

                            if (portEnd < portStart)
                            {
                                WinFormHelper.ShowError("请填写正确端口范围");
                                return;
                            }

                            var progress = ((ipEnd + 1 - ipStart) * (portEnd + 1 - portStart));
                            if (progress > int.MaxValue)
                            {
                                WinFormHelper.ShowError("Ip地址范围过大");
                                return;
                            }
                            pgbPortScanerProgress.Minimum = 0;
                            pgbPortScanerProgress.Maximum = (int)progress;
                            pgbPortScanerProgress.Value   = 0;

                            System.Diagnostics.Debug.WriteLine("[Form主线程]ThreadId:{0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
                            portScaner = new PortScaner(txtPortScanerIpStart.Text, txtPortScanerIpEnd.Text, portStart, portEnd, tbPortScanerTimeOut.Value, Convert.ToInt32(txtPortScanerTaskNum.Text));
                            if (portScaner != null)
                            {
                                portScaner.TaskProgress.ProgressChanged += PortScanerStatusProgressEvent;
                                portScaner.ScanProgress.ProgressChanged += PortScanerIpListProgressEvent;

                                portScaner.Action();
                            }
                        }
                    }
                    else
                    {
                        WinFormHelper.ShowError("请输入有效的IP地址范围");
                        return;
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                WinFormHelper.ShowError("请输入有效的IP地址");
                return;
            }
        }