Exemplo n.º 1
0
        private void btnNewAES_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在创建对称密钥...";
            string rText = Enc.getAESkey(int.Parse(txtAESKeyLength.Text));

            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "创建对称密钥失败";
                MessageBox.Show(Enc.getErrorOnce(), "创建对称密钥失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "创建对称密钥完成。";
                txtAES.Text = rText;
                tabControl1.SelectedIndex = 2;
            }
        }
Exemplo n.º 2
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;
        }