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))); }
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; } }
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)))); }
public static string TripleDesDecrypt(this string value, byte[] password, byte[] iv) { return(TripleDes.TripleDesDecrypt(value, password, iv)); }