KeePassLib.Cryptography.HashingStreamEx.Close C# (CSharp) Method

Close() public method

public Close ( ) : void
return void
        public override void Close()
        {
            if(m_hash != null)
            {
                try
                {
                    m_hash.TransformFinalBlock(new byte[0], 0, 0);

                    m_pbFinalHash = m_hash.Hash;
                }
                catch(Exception) { Debug.Assert(false); }

                m_hash = null;
            }

            m_sBaseStream.Close();
        }

Usage Example

        public override void Run()
        {
            try
            {
                IOConnectionInfo ioc = _app.GetDb().Ioc;
                IFileStorage fileStorage = _app.GetFileStorage(ioc);
                if (fileStorage is CachingFileStorage)
                {
                    throw new Exception("Cannot sync a cached database!");
                }
                StatusLogger.UpdateMessage(UiStringKey.CheckingDatabaseForChanges);

                //download file from remote location and calculate hash:
                StatusLogger.UpdateSubMessage(_app.GetResourceString(UiStringKey.DownloadingRemoteFile));

                MemoryStream remoteData = new MemoryStream();
                using (
                    HashingStreamEx hashingRemoteStream = new HashingStreamEx(fileStorage.OpenFileForRead(ioc), false,
                                                                                new SHA256Managed()))
                {
                    hashingRemoteStream.CopyTo(remoteData);
                    hashingRemoteStream.Close();

                    if (!MemUtil.ArraysEqual(_app.GetDb().KpDatabase.HashOfFileOnDisk, hashingRemoteStream.Hash))
                    {
                        _app.TriggerReload(_context);
                        Finish(true);
                    }
                    else
                    {
                        Finish(true, _app.GetResourceString(UiStringKey.RemoteDatabaseUnchanged));
                    }
                }

            }
            catch (Exception e)
            {
                Finish(false, e.Message);
            }
        }
All Usage Examples Of KeePassLib.Cryptography.HashingStreamEx::Close