Пример #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    // Dispose managed objects

                    if (Slots != null)
                    {
                        for (int i = 0; i < Slots.Count; i++)
                        {
                            Slots[i].Dispose();
                            Slots[i] = null;
                        }
                    }

                    if (_pkcs11Library != null)
                    {
                        _pkcs11Library.Dispose();
                        _pkcs11Library = null;
                    }
                }

                // Dispose unmanaged objects

                _disposed = true;
            }
        }
Пример #2
0
 public override void Dispose()
 {
     if (session != null)
     {
         session.Dispose();
     }
     if (pkcs11Library != null)
     {
         pkcs11Library.Dispose();
     }
 }
Пример #3
0
        public void _01_BasicPkcs11DisposeTest()
        {
            // Unmanaged PKCS#11 library is usually loaded by the constructor of class implementing IPkcs11Library interface.
            // Every PKCS#11 library needs to be initialized with C_Initialize method which is also called automatically by the constructor mentioned above.
            IPkcs11Library pkcs11Library = Settings.Factories.Pkcs11LibraryFactory.LoadPkcs11Library(Settings.Factories, Settings.Pkcs11LibraryPath, Settings.AppType);

            // Do something interesting

            // Unmanaged PKCS#11 library is usually unloaded by Dispose() method of class implementing IPkcs11Library interface.
            // C_Finalize should be the last call made by an application and it is also called automatically by Dispose() method mentioned above.
            pkcs11Library.Dispose();
        }
Пример #4
0
 /// <summary></summary>
 public void Dispose()
 {
     if (_AesServices != null)
     {
         _AesServices.Clear();
         _AesServices = null;
     }
     if (_MD5Services != null)
     {
         _MD5Services.Dispose();
         _MD5Services = null;
     }
     if (_SHA1Services != null)
     {
         _SHA1Services.Dispose();
         _SHA1Services = null;
     }
     if (_SHA256Services != null)
     {
         _SHA256Services.Dispose();
         _SHA256Services = null;
     }
     if (_SHA384Services != null)
     {
         _SHA384Services.Dispose();
         _SHA384Services = null;
     }
     if (_SHA512Services != null)
     {
         _SHA512Services.Dispose();
         _SHA512Services = null;
     }
     if (_Pkcs11Library != null)
     {
         _Pkcs11Library.Dispose();
         _Pkcs11Library = null;
     }
     if (_Randomness != null)
     {
         _Randomness.Dispose();
         _Randomness = null;
     }
     if (_RsaServices != null)
     {
         _RsaServices.Clear();
         _RsaServices = null;
     }
 }
Пример #5
0
        public void Initialize(string libraryFilePath)
        {
            if (Factories == null)
            {
                Factories = new Pkcs11InteropFactories();
            }

            if (PKCS11Library != null)
            {
                PKCS11Library.Dispose();
            }

            _libraryFilePath = libraryFilePath;
            PKCS11Library    = Factories.Pkcs11LibraryFactory.LoadPkcs11Library(Factories, LibraryFilePath, AppType.MultiThreaded);

            Initialized?.Invoke(this, new EventArgs());
        }
        /// <summary>
        /// Disposes object
        /// </summary>
        /// <param name="disposing">Flag indicating whether managed resources should be disposed</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Dispose managed objects

                    if (_pkcs11Library != null)
                    {
                        _pkcs11Library.Dispose();
                        _pkcs11Library = null;
                    }
                }

                // Dispose unmanaged objects

                _disposed = true;
            }
        }
Пример #7
0
        /// <summary>
        /// Constructs internal context for Pkcs11X509Store class
        /// </summary>
        /// <param name="libraryPath">Name of or path to PKCS#11 library</param>
        /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param>
        /// <returns>Internal context for Pkcs11X509Store class</returns>
        private Pkcs11X509StoreContext GetStoreContext(string libraryPath, IPinProvider pinProvider)
        {
            Pkcs11InteropFactories factories = new Pkcs11InteropFactories();

            IPkcs11Library pkcs11Library = null;

            try
            {
                pkcs11Library = factories.Pkcs11LibraryFactory.LoadPkcs11Library(factories, libraryPath, AppType.MultiThreaded);
                var storeInfo = new Pkcs11X509StoreInfo(libraryPath, pkcs11Library.GetInfo());
                return(new Pkcs11X509StoreContext(pkcs11Library, storeInfo, pinProvider));
            }
            catch
            {
                if (pkcs11Library != null)
                {
                    pkcs11Library.Dispose();
                    pkcs11Library = null;
                }

                throw;
            }
        }
Пример #8
0
 public void Dispose()
 {
     CloseSession();
     slot = null;
     pkcs11Library?.Dispose();
 }