public void ServiceCanBeConfigured()
        {
            NameValueCollection settings          = new NameValueCollection();
            DataProtectionCryptographyService svc = new DataProtectionCryptographyService();

            svc.Configure(settings);
        }
        public void ServiceClearsSettingsAfterConfigured()
        {
            byte[] entropy = { 1, 2, 3, 4 };
            NameValueCollection settings = new NameValueCollection();

            settings["Entropy"] = Convert.ToBase64String(entropy);
            DataProtectionCryptographyService svc = new DataProtectionCryptographyService();

            svc.Configure(settings);

            Assert.AreEqual(0, settings.Count);
        }
        public void DecryptUsingEntropy()
        {
            byte[] userData = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };
            byte[] entropy  = { 1, 2, 3, 4 };
            NameValueCollection settings = new NameValueCollection();

            settings["Entropy"] = Convert.ToBase64String(entropy);
            DataProtectionCryptographyService svc = new DataProtectionCryptographyService();

            svc.Configure(settings);
            byte[] cipherData = ProtectedData.Protect(userData, entropy, DataProtectionScope.CurrentUser);

            byte[] recovered = svc.DecryptSymmetric(cipherData);

            Assert.AreEqual(Convert.ToBase64String(userData), Convert.ToBase64String(recovered));
        }
        public void ThrowsIfConfiguredWithNullSettings()
        {
            DataProtectionCryptographyService svc = new DataProtectionCryptographyService();

            svc.Configure(null);
        }