Example #1
0
        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);
            }
        }
Example #4
0
        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);
                }
            }
        }
Example #5
0
        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);
        }
Example #6
0
 /// <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)));
 }
Example #7
0
 /// <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)));
 }
Example #8
0
 public void DecryptBlockThrowsArgumentNullExceptionIfPasswordIsNull()
 {
     BlockEncrypter.DecryptBlock("blah blah blah blah blah blah", null);
 }
Example #9
0
 public void DecryptBlockThrowsArgumentNullExceptionIfTextToDecryptIsNull()
 {
     BlockEncrypter.DecryptBlock(null, null);
 }
Example #10
0
        public void EncryptBlockEncryptsTextWithAPasswordAndResultIsNotNull()
        {
            string encrypted = BlockEncrypter.EncryptBlock("This is my message to encrypt.", Encoding.ASCII.GetBytes("Pa55w0rd"));

            Assert.IsNotNull(encrypted);
        }