Example #1
0
        private void Button4_Click(object sender, EventArgs e)
        {
            SM4Utils sm4 = new SM4Utils();

            //sm4.secretKey = "JeF8U9wHFOMfs2Y8";
            sm4.secretKey = textBox1.Text;
            sm4.hexString = false;
            byte[] bytedata;
            bytedata = Encoding.Default.GetBytes(textBox3.Text);
            string plain_data = sm4.Decrypt_ECB(Encoding.Default.GetString(bytedata));

            byte[] plain_bytedata = Encoding.Default.GetBytes(plain_data);

            //MessageBox.Show(plain_data, "解密结果");
            textBox4.Text = plain_data;
        }
Example #2
0
        private void Button3_Click(object sender, EventArgs e)
        {
            SM4Utils sm4 = new SM4Utils();

            //sm4.secretKey = "JeF8U9wHFOMfs2Y8";
            sm4.secretKey = textBox1.Text;
            sm4.hexString = false;
            byte[] bytedata;
            bytedata = Encoding.Default.GetBytes(@"laner");

            string cipher_data = sm4.Encrypt_ECB(Encoding.Default.GetString(bytedata));

            byte[] cipher_bytedata = Encoding.Default.GetBytes(cipher_data);

            //string code = cipher_data;
            // MessageBox.Show(cipher_data,"密文");
            textBox3.Text = cipher_data;
        }
Example #3
0
        private void Button2_Click(object sender, EventArgs e)
        {
            SM4Utils sm4 = new SM4Utils();

            //sm4.secretKey = "JeF8U9wHFOMfs2Y8";
            sm4.secretKey = textBox1.Text;
            sm4.hexString = false;
            byte[] bytedata = Encoding.Default.GetBytes(textBox3.Text);
            byte[] temp_iv  = new byte[16];

            byte[] file_bytedata = new byte[bytedata.Length - 16];
            Array.Copy(bytedata, temp_iv, 16);
            sm4.iv = Encoding.Default.GetString(temp_iv);
            Array.Copy(bytedata, 16, file_bytedata, 0, (bytedata.Length - 16));
            string plain_data = sm4.Decrypt_CBC(Encoding.Default.GetString(file_bytedata));

            // MessageBox.Show(plain_data, "解密结果");
            textBox4.Text = plain_data;
        }
Example #4
0
        private void Button1_Click(object sender, EventArgs e)
        {
            SM4Utils sm4 = new SM4Utils();

            //sm4.secretKey = "JeF8U9wHFOMfs2Y8";
            sm4.secretKey = textBox1.Text;
            sm4.hexString = false;
            tempiv        = GetRandomString(16, true, true, true, false, null).ToLower();

            sm4.iv = tempiv;
            byte[] bytedata;
            bytedata = Encoding.Default.GetBytes(textBox2.Text);

            string cipher_data    = sm4.Encrypt_CBC(Encoding.Default.GetString(bytedata));
            string cipher_data_iv = sm4.iv + cipher_data;

            byte[] cipher_bytedata    = Encoding.Default.GetBytes(cipher_data);
            byte[] cipher_bytedata_iv = Encoding.Default.GetBytes(cipher_data_iv);

            string code = Encoding.Default.GetString(cipher_bytedata_iv);

            textBox3.Text = code;
            // MessageBox.Show(Encoding.Default.GetString(cipher_bytedata_iv));
        }