Exemple #1
0
        private void btnEncTxt_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在加密...";
            string rText = "";

            if (radioKeyMode1.Checked)
            {
                rText = Enc.encryptAESData(tempAESKeyFile, txtText.Text, false, txtSecMode.Text);
            }
            else
            {
                rText = Enc.encryptData(tempPublicKeyFile, txtText.Text);
            }
            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "加密操作失败";
                MessageBox.Show(Enc.getErrorOnce(), "加密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "加密完成";
                if (checkBase64.Checked)
                {
                    byte[] rTextB64 = Encoding.Default.GetBytes(rText);
                    rText = Convert.ToBase64String(rTextB64);
                }
                txtText.Text = rText;
                tabControl1.SelectedIndex = 3;
            }
        }
Exemple #2
0
        private void btnEncFile_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在加密...";
            string rText = "";

            if (radioKeyMode1.Checked)
            {
                rText = Enc.encryptAESData(tempAESKeyFile, txtFrom.Text, true, txtSecMode.Text, txtTo.Text);
            }
            else
            {
                rText = Enc.encryptData(tempPublicKeyFile, txtFrom.Text, true, txtTo.Text);
            }
            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "加密操作失败";
                MessageBox.Show(Enc.getErrorOnce(), "加密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "加密完成";
            }
        }
Exemple #3
0
        static private void encryptThreadRun()
        {
            encryptThreadWorking = true;
            string nowThreadID = threadID.ToString();

            printf("启动文件加密线程 " + nowThreadID + " ...", 0);
            foreach (string file in getTempFiles(imgType))
            {
                printf("正在处理文件 " + file + " ...", 0);
                string[] extFileName = file.Split('.');
                extFileName[extFileName.Length - 1] = keyType;
                string aesKey = string.Join(".", extFileName);
                extFileName[extFileName.Length - 1] = encType;
                string encFile = string.Join(".", extFileName);
                extFileName[extFileName.Length - 1] = encKeyType;
                string encKeyFile = string.Join(".", extFileName);
                printf("生成对称密钥 " + aesKey + " ...", 0);
                Enc.getAESkey(aesLength, aesKey);
                string err = Enc.getErrorOnce();
                if (err.Length > 0)
                {
                    printf(err, 3);
                    return;
                }
                printf("使用对称密钥加密文件到 " + encFile + " ...", 0);
                Enc.encryptAESData(aesKey, file, true, symmetric, encFile);
                err = Enc.getErrorOnce();
                if (err.Length > 0)
                {
                    printf(err, 3);
                    return;
                }
                printf("加密对称密钥到 " + encKeyFile + " ...", 0);
                Enc.encryptData(publicKey, aesKey, true, encKeyFile);
                err = Enc.getErrorOnce();
                if (err.Length > 0)
                {
                    printf(err, 3);
                    return;
                }
                printf("删除未加密密钥 " + aesKey + " ...", 0);
                if (File.Exists(aesKey))
                {
                    File.Delete(aesKey);
                }
                printf("删除未加密文件 " + file + " ...", 0);
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                if (!netuploadThreadWorking && uURL.Length > 0)
                {
                    ThreadStart encryptRef    = new ThreadStart(uploadThreadRun);
                    Thread      encryptThread = new Thread(encryptRef);
                    encryptThread.Name = "encryptThread" + (threadID++).ToString();
                    encryptThread.Start();
                }
                Thread.Sleep(workSleepTime);
            }
            printf("结束文件加密线程 " + nowThreadID + " 。", 0);
            encryptThreadWorking = false;
        }