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

            return
                (Encoding.UTF8.GetString(TripleDes.TripleDesDecrypt(Base64.DecodeToArray(value), passBytes, passBytes)));
        }
Exemplo n.º 2
0
        public static string TripleDesEncryptToArray(this string value, string password, string iv)
        {
            var bytes     = Encoding.UTF8.GetBytes(value);
            var encrypted = TripleDes.TripleDesEncrypt(Encoding.UTF8.GetChars(bytes), Encoding.ASCII.GetBytes(password),
                                                       Encoding.ASCII.GetBytes(iv));

            return(encrypted.ToArrayString());
        }
Exemplo n.º 3
0
        public static string TripleDesEncrypt(this string value, string password)
        {
            var passBytes = Encoding.ASCII.GetBytes(password);

            return
                (Base64.Encode(TripleDes.TripleDesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(value)),
                                                          passBytes, passBytes)));
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
        private void Decrypt()
        {
            rtb_PlainText.TextChanged -= rtb_PlainText_TextChanged;
            rtb_PlainText.Text         = String.Empty;
            try
            {
                switch (cypherMode)
                {
                case CypherMode.Base64:
                    rtb_PlainText.Text = rtb_CypherText.Text.Base64Decode();
                    break;

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

                case CypherMode.Des:
                    if (chk_ByteArrayValues.Checked)
                    {
                        var byteStrings = rtb_CypherText.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(Des.DesDecrypt(bytes, Encoding.ASCII.GetBytes(tb_Password.Text), Encoding.ASCII.GetBytes(tb_IV.Text)));
                    }
                    else
                    {
                        rtb_PlainText.Text = rtb_CypherText.Text.DesDecrypt(tb_Password.Text, tb_IV.Text);
                    }
                    break;

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

                case CypherMode.TripleDes:
                    if (chk_ByteArrayValues.Checked)
                    {
                        var bytes = rtb_CypherText.Text.StringToByteArray();
                        if (chk_KeyAndIVInByteArrayFormat.Checked)
                        {
                            var keyBytes = tb_Password.Text.StringToByteArray();
                            var ivBytes  = tb_IV.Text.StringToByteArray();
                            rtb_PlainText.Text = Encoding.UTF8.GetString(TripleDes.TripleDesDecrypt(bytes, keyBytes, ivBytes));
                        }
                        else
                        {
                            rtb_PlainText.Text = Encoding.UTF8.GetString(TripleDes.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_CypherText.Text.TripleDesDecrypt(keyBytes, ivBytes);
                        }
                        else
                        {
                            rtb_PlainText.Text = rtb_CypherText.Text.TripleDesDecrypt(tb_Password.Text, tb_IV.Text);
                        }
                    }
                    break;

                case CypherMode.Xor:
                    rtb_PlainText.Text = rtb_CypherText.Text.XorCrypt(tb_Password.Text);
                    break;
                }
            }
            catch (Exception ex)
            {
                rtb_PlainText.Text = ex.Message;
            }
            finally
            {
                rtb_PlainText.TextChanged += rtb_PlainText_TextChanged;
            }
        }
Exemplo n.º 6
0
 public static string TripleDesEncrypt(this string value, byte[] password, byte[] iv)
 {
     return(TripleDes.TripleDesEncrypt(value, password, iv));
 }
Exemplo n.º 7
0
 public static string TripleDesEncrypt(this string value, string password, string iv)
 {
     return
         (Base64.Encode(TripleDes.TripleDesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(value)),
                                                   Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(iv))));
 }
Exemplo n.º 8
0
 public static string TripleDesDecrypt(this string value, string password, string iv)
 {
     return(Encoding.UTF8.GetString(TripleDes.TripleDesDecrypt(Base64.DecodeToArray(value), Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(iv))));
 }