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.");
            }
        }
        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.");
            }
        }
예제 #3
0
 protected override void Dispose(bool disposing)
 {
     if (!m_disposed)
     {
         // the key is persisted and we do not want it persisted
         if ((persisted) && (!persistKey))
         {
             store.Remove();                             // delete the container
         }
         if (dsa != null)
         {
             dsa.Clear();
         }
         // call base class
         // no need as they all are abstract before us
         m_disposed = true;
     }
 }
        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.");
            }
        }