public void CspFlagsDefaultMachine()
        {
            try
            {
                CspParameters cp = new CspParameters(-7, "Provider", "Container");
                cp.Flags = CspProviderFlags.UseDefaultKeyContainer | CspProviderFlags.UseMachineKeyStore;
                KeyPairPersistence kpp = new KeyPairPersistence(cp, "<keypair/>");
                kpp.Save();

                Assert.IsTrue(File.Exists(kpp.Filename), "Save-Exists");
                KeyPairPersistence kpp2 = new KeyPairPersistence(cp);
                Assert.IsTrue(kpp2.Load(), "Load");

                Compare(kpp, kpp2);
                kpp.Remove();
                Assert.IsFalse(File.Exists(kpp.Filename), "Remove-!Exists");
            }
            catch (CryptographicException ce)
            {
                // not everyone can write to the machine store
                if (!(ce.InnerException is UnauthorizedAccessException))
                {
                    throw;
                }
                Assert.Ignore("Access denied to key containers files.");
            }
            catch (UnauthorizedAccessException)
            {
                Assert.Ignore("Access denied to key containers files.");
            }
        }
Exemple #2
0
        // private stuff

        private void OnKeyGenerated(object sender, EventArgs e)
        {
            // the key isn't persisted and we want it persisted
            if ((persistKey) && (!persisted))
            {
                // save the current keypair
                store.KeyValue = this.ToXmlString(!dsa.PublicOnly);
                store.Save();
                persisted = true;
            }
        }
Exemple #3
0
        public void Save()
        {
            var csp = new CspParameters(1);

            if (machineStore)
            {
                csp.Flags |= CspProviderFlags.UseMachineKeyStore;
            }
            csp.ProviderName     = String.Empty;
            csp.KeyContainerName = ContainerName;

            var kpp = new KeyPairPersistence(csp, KeyValue);

            kpp.Save();
        }
        public void CspTypeProvider()
        {
            try {
                CspParameters      cp  = new CspParameters(-2, "Provider");
                KeyPairPersistence kpp = new KeyPairPersistence(cp, "<keypair/>");
                kpp.Save();

                Assert.IsTrue(File.Exists(kpp.Filename), "Save-Exists");
                // we didn't supply a name so we can't load it back

                kpp.Remove();
                Assert.IsFalse(File.Exists(kpp.Filename), "Remove-!Exists");
            }
            catch (UnauthorizedAccessException) {
                Assert.Ignore("Access denied to key containers files.");
            }
        }
        public void CspTypeProviderContainer()
        {
            try {
                CspParameters      cp  = new CspParameters(-3, "Provider", "Container");
                KeyPairPersistence kpp = new KeyPairPersistence(cp, "<keypair/>");
                kpp.Save();

                Assert.IsTrue(File.Exists(kpp.Filename), "Save-Exists");
                KeyPairPersistence kpp2 = new KeyPairPersistence(cp);
                Assert.IsTrue(kpp2.Load(), "Load");

                Compare(kpp, kpp2);
                kpp.Remove();
                Assert.IsFalse(File.Exists(kpp.Filename), "Remove-!Exists");
            }
            catch (UnauthorizedAccessException) {
                Assert.Ignore("Access denied to key containers files.");
            }
        }