public void DecryptBlockDecryptsBlockBackToOriginalPlainText() { const string originalMessage = "This is my message to encrypt."; string encrypted = BlockEncrypter.EncryptBlock(originalMessage, Encoding.ASCII.GetBytes("Pa55w0rd")); string decrypted = BlockEncrypter.DecryptBlock(encrypted, Encoding.ASCII.GetBytes("Pa55w0rd")); Assert.AreEqual(originalMessage, decrypted); }
private void EncryptText() { SetPasswordAndStatusBar(false); try { encryptedText.Text = BlockEncrypter.EncryptBlock(textToEncrypt.Text, _passwordEntry.Password.CombinedPasswords); } catch (Exception) { encryptedText.Text = ""; MessageBox.Show(Resources.TextShredderMainForm_EncryptText_There_was_an_error_encrypting_the_message_, Resources.TextShredderMainForm_EncryptText_Encryption_Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void DecryptText() { SetPasswordAndStatusBar(false); try { decryptedText.Text = BlockEncrypter.DecryptBlock(textToDecrypt.Text, _passwordEntry.Password.CombinedPasswords); } catch (CryptographicException ex) { decryptedText.Text = ""; MessageBox.Show(ex.Message, Resources.TextShredderMainForm_DecryptText_Message_Tamper_Alert, MessageBoxButtons.OK, MessageBoxIcon.Stop); } catch (Exception) { decryptedText.Text = ""; MessageBox.Show(Resources.TextShredderMainForm_DecryptText_There_was_an_error_decrypting_the_message_, Resources.TextShredderMainForm_DecryptText_Decryption_Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
static string GetConfigurationValue(string key, bool cryptMe) { // Read values from configuration string setting = ConfigurationManager.AppSettings[key]; if (setting == "") { return("Error"); } else { if (crypt == true & cryptMe == true) { return(BlockEncrypter.DecryptStringBlock(setting, Encoding.ASCII.GetBytes("Pa55w0rd"))); } else { return(setting); } } }
public static void SetAppConfigValue(string XPathQuery, string value, string filename, bool cryptValue) { XmlDocument doc = new XmlDocument(); try { doc.Load(filename); } catch { Console.Write("Can't find " + filename); } try { XmlElement itemTitle = (XmlElement)doc.SelectSingleNode(XPathQuery); string val = ""; if (crypt == true & cryptValue == true) { val = BlockEncrypter.EncryptStringBlock(value, Encoding.ASCII.GetBytes("Pa55w0rd")); } else { val = value; } itemTitle.Attributes["value"].Value = val; } catch { Console.Write("Can't add " + value + " to " + XPathQuery + " in " + filename); } doc.Save(filename); ConfigurationManager.RefreshSection("appSettings"); //Console.Write("Saving " + filename); }
/// <summary> /// Decrypt a ciphertext string using the BlockEncrypter library. /// </summary> /// <param name="ciphertext"></param> /// <returns></returns> public static string Decrypt(string ciphertext) { return(BlockEncrypter.DecryptStringBlock(ciphertext, Encoding.ASCII.GetBytes(ApplicationSettings.EncryptionKey))); }
/// <summary> /// Encrypts a plaintext string using the BlockEncrypter library. /// </summary> /// <param name="plaintext"></param> /// <returns></returns> public static string Encrypt(string plaintext) { return(BlockEncrypter.EncryptStringBlock(plaintext, Encoding.ASCII.GetBytes(ApplicationSettings.EncryptionKey))); }
public void DecryptBlockThrowsArgumentNullExceptionIfPasswordIsNull() { BlockEncrypter.DecryptBlock("blah blah blah blah blah blah", null); }
public void DecryptBlockThrowsArgumentNullExceptionIfTextToDecryptIsNull() { BlockEncrypter.DecryptBlock(null, null); }
public void EncryptBlockEncryptsTextWithAPasswordAndResultIsNotNull() { string encrypted = BlockEncrypter.EncryptBlock("This is my message to encrypt.", Encoding.ASCII.GetBytes("Pa55w0rd")); Assert.IsNotNull(encrypted); }