예제 #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;
            }
        }
예제 #2
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;
            }
        }
예제 #3
0
        private void btnNewPubKey_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在提取公钥...";
            string rText = Enc.getPublicKey(txtPrivatePEM.Text);

            tabControl1.SelectedIndex = 1;
            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "提取公钥操作失败";
                MessageBox.Show(Enc.getErrorOnce(), "提取公钥操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "提取公钥完成。";
                txtPublicPEM.Text          = rText;
            }
        }
예제 #4
0
        private void btnNewPriKey_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在创建私钥...";
            string rText = Enc.genPrivateKey(int.Parse(txtKeyLength.Text));

            tabControl1.SelectedIndex = 0;
            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "创建私钥操作失败";
                MessageBox.Show(Enc.getErrorOnce(), "创建私钥操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "创建私钥完成。";
                txtPrivatePEM.Text         = rText;
            }
        }
예제 #5
0
        private void btnDecTxt_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在解密...";
            string rText = txtText.Text;

            if (checkBase64.Checked)
            {
                try
                {
                    byte[] rTextB64 = Convert.FromBase64String(rText);
                    rText = Encoding.Default.GetString(rTextB64);
                }
                catch (Exception err)
                {
                    toolStripStatusLabel1.Text = err.Message;
                    MessageBox.Show(toolStripStatusLabel1.Text, "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (radioKeyMode1.Checked)
            {
                rText = Enc.decryptionAESData(tempAESKeyFile, rText);
            }
            else
            {
                rText = Enc.decryptionData(tempPrivateKeyFile, rText);
            }
            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "解密操作失败";
                MessageBox.Show(Enc.getErrorOnce(), "解密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "解密完成";
                txtText.Text = rText;
                tabControl1.SelectedIndex = 3;
            }
        }
예제 #6
0
        private void btnDecFile_Click(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "正在解密...";
            string rText = "";

            if (radioKeyMode1.Checked)
            {
                rText = Enc.decryptionAESData(tempAESKeyFile, txtFrom.Text, true, "aes-256-cbc", txtTo.Text);
            }
            else
            {
                rText = Enc.decryptionData(tempPrivateKeyFile, txtFrom.Text, true, txtTo.Text);
            }
            if (rText.Length == 0 && Enc.isErrorInfo())
            {
                toolStripStatusLabel1.Text = "解密操作失败";
                MessageBox.Show(Enc.getErrorOnce(), "解密操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                toolStripStatusLabel1.Text = "解密完成";
            }
        }
예제 #7
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 = "加密完成";
            }
        }
예제 #8
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;
        }