protected void Dispose(bool disposing) { if (disposing) { HashAlgorithm?.Dispose(); } }
public void Dispose() { _rsa?.Dispose(); _rsa = null; _sha?.Dispose(); _sha = null; }
/// <inheritdoc/> public void Dispose() { lock (stream) { if (!disposed) { disposed = true; stream?.Dispose(); hasher?.Dispose(); } } }
private bool _disposedValue; // To detect redundant calls void Dispose(bool disposing) { if (_disposedValue) { return; } if (disposing) { _hasher?.Dispose(); } _disposedValue = true; }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). _hashAlgorithm?.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
/// <summary> /// Determines if the file given is the same file that the document references. It does the comparison /// using the file hash provided in the document against the computed hash of the file on disk. /// </summary> private bool FileMatchesDocumentReference(Document doc, String file) { HashAlgorithm hashingAlgorithm = null; FileStream fileStream = null; try { switch (doc.HashAlgorithm) { case DocumentHashAlgorithm.MD5: hashingAlgorithm = MD5.Create(); break; case DocumentHashAlgorithm.SHA1: hashingAlgorithm = SHA1.Create(); break; case DocumentHashAlgorithm.SHA256: hashingAlgorithm = SHA256.Create(); break; case DocumentHashAlgorithm.None: default: // The file either doesn't have a hash or it's an unknown type of hash. In either case return false for no match. return(false); } if (!File.Exists(file)) { // The file doesn't exist, it can't be a match return(false); } fileStream = File.OpenRead(file); byte[] computedHash = hashingAlgorithm.ComputeHash(fileStream); return(computedHash.SequenceEqual(doc.Hash)); } finally { // Cleanup our IDisposable objects hashingAlgorithm?.Dispose(); fileStream?.Dispose(); } }
protected override void DisposeManaged() { _hasher?.Dispose(); base.DisposeManaged(); }
public void Dispose() { _rsa?.Dispose(); _hasher?.Dispose(); }
public void Dispose() { _hashAlgorithm?.Dispose(); _output?.Dispose(); }
public void Dispose() { _Hash?.Dispose(); _Hash = null; }
public void Dispose() { _symmetricAlgorithm?.Dispose(); _hashAlgorithm?.Dispose(); }
public void Dispose() { checksumStream?.Dispose(); checksum?.Dispose(); }
protected virtual void Dispose(bool dispose) { crypto.Dispose(); hash.Dispose(); }
public void Dispose() { _native.Dispose(); }