public void ClearAnyRemnantKeys()
        {
            var keyLocation = new PasswordEncryptionKeyLocation(CatalogueRepository);

            if (keyLocation.GetKeyFileLocation() != null)
            {
                keyLocation.DeleteKey();
            }
        }
        protected override void SetUp()
        {
            base.SetUp();

            var keyLocation = new PasswordEncryptionKeyLocation(CatalogueRepository);

            if (keyLocation.GetKeyFileLocation() != null)
            {
                keyLocation.DeleteKey();
            }
        }
        public void CreateKeyFile()
        {
            var keyLocation = new PasswordEncryptionKeyLocation(CatalogueRepository);
            var file        = keyLocation.CreateNewKeyFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "my.key"));

            Console.WriteLine("Key file location is:" + file.FullName);
            Console.WriteLine("Text put into file is:" + Environment.NewLine + File.ReadAllText(file.FullName));

            Assert.IsTrue(file.FullName.EndsWith("my.key"));

            Assert.AreEqual(file.FullName, keyLocation.GetKeyFileLocation());
            keyLocation.DeleteKey();

            Assert.IsNull(keyLocation.GetKeyFileLocation());
        }
        private void btnDeleteKeyLocation_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show(
                        "You are about to delete the RDMPs record of where the key file is to decrypt passwords, if you do this all currently configured password will become inaccessible (EVEN IF YOU CREATE A NEW KEY, YOU WILL NOT BE ABLE TO GET THE CURRENT PASSWORDS BACK), are you sure you want to do this?",
                        "Confirm deleting location of decryption key file", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                {
                    _location.DeleteKey();
                }

                SetEnabledness();
            }
            catch (Exception exception)
            {
                ExceptionViewer.Show(exception);
            }
        }
        public void Encrypt()
        {
            string value = "MyPieceOfText";

            Console.WriteLine("String is:" + value);

            EncryptedString encrypter = new EncryptedString(CatalogueRepository);

            Assert.IsFalse(encrypter.IsStringEncrypted(value));

            //should do pass through encryption
            encrypter.Value = value;
            Assert.AreNotEqual(value, encrypter.Value);
            Assert.AreEqual(value, encrypter.GetDecryptedValue());

            Console.WriteLine("Encrypted (stock) is:" + encrypter.Value);
            Console.WriteLine("Decrypted (stock) is:" + encrypter.GetDecryptedValue());

            var keyLocation = new PasswordEncryptionKeyLocation(CatalogueRepository);

            keyLocation.CreateNewKeyFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "my.key"));
            var p = keyLocation.OpenKeyFile();

            CatalogueRepository.EncryptionManager.ClearAllInjections();

            var s         = CatalogueRepository.EncryptionManager.GetEncrypter();
            var exception = Assert.Throws <CryptographicException>(() => s.Decrypt(encrypter.Value));

            Assert.IsTrue(exception.Message.StartsWith("Could not decrypt an encrypted string, possibly you are trying to decrypt it after having changed the PrivateKey "));

            string encrypted = s.Encrypt(value);

            Console.WriteLine("Encrypted (with key) is:" + encrypted);
            Console.WriteLine("Decrypted (with key) is:" + s.Decrypt(encrypted));

            Assert.IsTrue(encrypter.IsStringEncrypted(encrypted));

            keyLocation.DeleteKey();
        }