Пример #1
0
        public static string DesEncrypt(this string value, string password)
        {
            var passBytes = Encoding.ASCII.GetBytes(password);

            return
                (Base64.Encode(Des.DesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(value)), passBytes,
                                              passBytes)));
        }
Пример #2
0
        private void Encrypt()
        {
            rtb_CypherText.TextChanged -= rtb_CipherText_TextChanged;
            rtb_CypherText.Text         = String.Empty;
            try
            {
                switch (cypherMode)
                {
                case CypherMode.Base64:
                    rtb_CypherText.Text = rtb_PlainText.Text.Base64Encode();
                    break;

                case CypherMode.Caesar:
                    rtb_CypherText.Text = rtb_PlainText.Text.CaesarEncrypt((int)nud_Key.Value);
                    break;

                case CypherMode.Des:
                    if (chk_ByteArrayValues.Checked)
                    {
                        var encryptedText  = new StringBuilder();
                        var encryptedBytes = Des.DesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(rtb_PlainText.Text)), Encoding.ASCII.GetBytes(tb_Password.Text), Encoding.ASCII.GetBytes(tb_IV.Text));
                        foreach (var encryptedByte in encryptedBytes)
                        {
                            encryptedText.AppendFormat("[{0}]", encryptedByte);
                        }
                        rtb_CypherText.Text = encryptedText.ToString();
                    }
                    else
                    {
                        rtb_CypherText.Text = rtb_PlainText.Text.DesEncrypt(tb_Password.Text, tb_IV.Text);
                    }
                    break;

                case CypherMode.Rotate:
                    rtb_CypherText.Text = rtb_PlainText.Text.RotateEncrypt((int)nud_Key.Value);
                    break;

                case CypherMode.TripleDes:
                    if (chk_ByteArrayValues.Checked)
                    {
                        if (chk_KeyAndIVInByteArrayFormat.Checked)
                        {
                        }
                        else
                        {
                            var encryptedText  = new StringBuilder();
                            var encryptedBytes = TripleDes.TripleDesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(rtb_PlainText.Text)), Encoding.ASCII.GetBytes(tb_Password.Text), Encoding.ASCII.GetBytes(tb_IV.Text));
                            foreach (var encryptedByte in encryptedBytes)
                            {
                                encryptedText.AppendFormat("[{0}]", encryptedByte);
                            }
                            rtb_CypherText.Text = encryptedText.ToString();
                        }
                    }
                    else
                    {
                        if (chk_KeyAndIVInByteArrayFormat.Checked)
                        {
                        }
                        else
                        {
                            rtb_CypherText.Text = rtb_PlainText.Text.TripleDesEncrypt(tb_Password.Text, tb_IV.Text);
                        }
                    }
                    break;

                case CypherMode.Xor:
                    rtb_CypherText.Text = rtb_PlainText.Text.XorCrypt(tb_Password.Text);
                    break;
                }
            }
            catch (Exception ex)
            {
                lbl_Error.Text = ex.Message;
            }
            finally
            {
                rtb_CypherText.TextChanged += rtb_CipherText_TextChanged;
            }
        }
Пример #3
0
 public static string DesEncrypt(this string value, string password, string iv)
 {
     return
         (Base64.Encode(Des.DesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(value)),
                                       Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(iv))));
 }