public void DecryptTest()
        {
            // Arrange
            var pass = "******";
            var pass2 = "This is a test key";
            var subject = new StringEncryption(pass);
            var subject2 = new StringEncryption(pass2);
            var originalString = "Testing123!£$";

            // Act
            var encryptedString1 = subject.Encrypt(originalString);
            var encryptedString2 = subject.Encrypt(originalString);
            var decryptedString1 = subject.Decrypt(encryptedString1);
            var decryptedString2 = subject.Decrypt(encryptedString2);

            var encryptedString3 = subject2.Encrypt(originalString);
            var encryptedString4 = subject2.Encrypt(originalString);
            var decryptedString3 = subject2.Decrypt(encryptedString3);
            var decryptedString4 = subject2.Decrypt(encryptedString4);

            // Assert
            Assert.AreEqual(originalString, decryptedString1, "Decrypted string should match original string");
            Assert.AreEqual(originalString, decryptedString2, "Decrypted string should match original string");
            Assert.AreEqual(originalString, decryptedString3, "Decrypted string should match original string");
            Assert.AreEqual(originalString, decryptedString4, "Decrypted string should match original string");
        }
        public void EncryptTest()
        {
            var pass = "******";
            var pass2 = "This is a test key";
            var subject = new StringEncryption(pass);
            var subject2 = new StringEncryption(pass2);
            var originalString = "Testing123!£$";

            // Act
            var encryptedString1 = subject.Encrypt(originalString);
            var encryptedString2 = subject.Encrypt(originalString);
            var encryptedString3 = subject.Encrypt(originalString);
            var encryptedString4 = subject.Encrypt(originalString);

            Assert.AreNotEqual(originalString, encryptedString1, "Encrypted string should not match original string");
            Assert.AreNotEqual(encryptedString1, encryptedString2, "String should never be encrypted the same twice");
            Assert.AreNotEqual(originalString, encryptedString3, "Encrypted string should not match original string");
            Assert.AreNotEqual(encryptedString3, encryptedString4, "String should never be encrypted the same twice");
        }
Пример #3
0
        private String doPossibleEncryption(Uri file, String rdl)
        {
            String extension = Path.GetExtension(file.LocalPath);
            if (extension.Equals(".encrypted"))
            {
                StringEncryption enc = new StringEncryption(Prompt.ShowDialog("Please enter passkey", "Passkey?"));
                try
                {
                    rdl = enc.Encrypt(rdl);
                }
                catch (Exception)
                {
                    MessageBox.Show(Properties.Resources.MDIChild_doPossibleEncryption_Unable_to_encrypt_file_);
                }

            }
            return rdl;
        }
Пример #4
0
        private String doPossibleDecryption(String rdl)
        {
            if (Path.GetExtension(_SourceFile.LocalPath).Equals(".encrypted"))
            {

                try
                {
                    StringEncryption enc = new StringEncryption(Prompt.ShowDialog("Please enter the passkey", "Passkey?"));
                    rdl = enc.Decrypt(rdl);
                }
                catch (Exception)
                {
                    MessageBox.Show(Properties.Resources.MDIChild_doPossibleDecryption_Incorrect_passkey_entered_);
                }
            }

            return rdl;
        }