public static string TripleDesEncryptToArray(this string value, string password, string iv) { var bytes = Encoding.UTF8.GetBytes(value); var encrypted = TripleDesCipher.TripleDesEncrypt(Encoding.UTF8.GetChars(bytes), Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(iv)); return(encrypted.ToArrayString()); }
public static string TripleDesEncrypt(this string value, string password) { var passBytes = Encoding.ASCII.GetBytes(password); return (Base64.Encode(TripleDesCipher.TripleDesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(value)), passBytes, passBytes))); }
public static string TripleDesEncrypt(this string value, byte[] password, byte[] iv) { return(TripleDesCipher.TripleDesEncrypt(value, password, iv)); }
public static string TripleDesEncrypt(this string value, string password, string iv) { return (Base64.Encode(TripleDesCipher.TripleDesEncrypt(Encoding.UTF8.GetChars(Encoding.UTF8.GetBytes(value)), Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(iv)))); }
private void Encrypt() { rtb_CipherText.TextChanged -= Rtb_CipherText_TextChanged; rtb_CipherText.Text = String.Empty; try { switch (cipherMode) { case CipherMode.Base64: rtb_CipherText.Text = rtb_PlainText.Text.Base64Encode(); break; case CipherMode.Caesar: rtb_CipherText.Text = rtb_PlainText.Text.CaesarEncrypt((int)nud_Key.Value); break; case CipherMode.Des: if (chk_ByteArrayValues.Checked) { var encryptedText = new StringBuilder(); var encryptedBytes = DesCipher.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_CipherText.Text = encryptedText.ToString(); } else { rtb_CipherText.Text = rtb_PlainText.Text.DesEncrypt(tb_Password.Text, tb_IV.Text); } break; case CipherMode.Rotate: rtb_CipherText.Text = rtb_PlainText.Text.RotateEncrypt((int)nud_Key.Value); break; case CipherMode.TripleDes: if (chk_ByteArrayValues.Checked) { if (chk_KeyAndIVInByteArrayFormat.Checked) { } else { var encryptedText = new StringBuilder(); var encryptedBytes = TripleDesCipher.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_CipherText.Text = encryptedText.ToString(); } } else { if (chk_KeyAndIVInByteArrayFormat.Checked) { } else { rtb_CipherText.Text = rtb_PlainText.Text.TripleDesEncrypt(tb_Password.Text, tb_IV.Text); } } break; case CipherMode.Xor: rtb_CipherText.Text = rtb_PlainText.Text.XorCrypt(tb_Password.Text); break; } } catch (Exception ex) { lbl_Error.Text = ex.Message; } finally { rtb_CipherText.TextChanged += Rtb_CipherText_TextChanged; } }