Exemplo n.º 1
0
        public static string DesDecrypt(this string value, string password)
        {
            var passBytes = Encoding.ASCII.GetBytes(password);

            return(Encoding.UTF8.GetString(DesCipher.DesDecrypt(Base64.DecodeToArray(value), passBytes, passBytes)));
        }
Exemplo n.º 2
0
 public static string DesDecrypt(this string value, string password, string iv)
 {
     return
         (Encoding.UTF8.GetString(DesCipher.DesDecrypt(Base64.DecodeToArray(value), Encoding.ASCII.GetBytes(password),
                                                       Encoding.ASCII.GetBytes(iv))));
 }
Exemplo n.º 3
0
        private void Decrypt()
        {
            rtb_PlainText.TextChanged -= Rtb_PlainText_TextChanged;
            rtb_PlainText.Text         = String.Empty;
            try
            {
                switch (cipherMode)
                {
                case CipherMode.Base64:
                    rtb_PlainText.Text = rtb_CipherText.Text.Base64Decode();
                    break;

                case CipherMode.Caesar:
                    rtb_PlainText.Text = rtb_CipherText.Text.CaesarDecrypt((int)nud_Key.Value);
                    break;

                case CipherMode.Des:
                    if (chk_ByteArrayValues.Checked)
                    {
                        var byteStrings = rtb_CipherText.Text.Replace("[", "").Split(']');
                        var bytes       = new byte[byteStrings.Length - 1];
                        for (var i = 0; i < bytes.Length; i++)
                        {
                            bytes[i] = Convert.ToByte(byteStrings[i]);
                        }
                        rtb_PlainText.Text = Encoding.UTF8.GetString(DesCipher.DesDecrypt(bytes, Encoding.ASCII.GetBytes(tb_Password.Text), Encoding.ASCII.GetBytes(tb_IV.Text)));
                    }
                    else
                    {
                        rtb_PlainText.Text = rtb_CipherText.Text.DesDecrypt(tb_Password.Text, tb_IV.Text);
                    }
                    break;

                case CipherMode.Rotate:
                    rtb_PlainText.Text = rtb_CipherText.Text.RotateDecrypt((int)nud_Key.Value);
                    break;

                case CipherMode.TripleDes:
                    if (chk_ByteArrayValues.Checked)
                    {
                        var bytes = rtb_CipherText.Text.StringToByteArray();
                        if (chk_KeyAndIVInByteArrayFormat.Checked)
                        {
                            var keyBytes = tb_Password.Text.StringToByteArray();
                            var ivBytes  = tb_IV.Text.StringToByteArray();
                            rtb_PlainText.Text = Encoding.UTF8.GetString(TripleDesCipher.TripleDesDecrypt(bytes, keyBytes, ivBytes));
                        }
                        else
                        {
                            rtb_PlainText.Text = Encoding.UTF8.GetString(TripleDesCipher.TripleDesDecrypt(bytes, Encoding.ASCII.GetBytes(tb_Password.Text), Encoding.ASCII.GetBytes(tb_IV.Text)));
                        }
                    }
                    else
                    {
                        if (chk_KeyAndIVInByteArrayFormat.Checked)
                        {
                            var keyBytes = tb_Password.Text.StringToByteArray();
                            var ivBytes  = tb_IV.Text.StringToByteArray();
                            rtb_PlainText.Text = rtb_CipherText.Text.TripleDesDecrypt(keyBytes, ivBytes);
                        }
                        else
                        {
                            rtb_PlainText.Text = rtb_CipherText.Text.TripleDesDecrypt(tb_Password.Text, tb_IV.Text);
                        }
                    }
                    break;

                case CipherMode.Xor:
                    rtb_PlainText.Text = rtb_CipherText.Text.XorCrypt(tb_Password.Text);
                    break;
                }
            }
            catch (Exception ex)
            {
                rtb_PlainText.Text = ex.Message;
            }
            finally
            {
                rtb_PlainText.TextChanged += Rtb_PlainText_TextChanged;
            }
        }