private static string CalculateLocalPackageHash(Stream contents) { if (contents.CanSeek && contents.CanRead) { contents.Seek(0, SeekOrigin.Begin); return(HashCalculator.Hash(contents)); } if (!(contents is FileStream fileStream)) { return(null); } // When a full package upload times out we get a stream here that is already disposed so we need to open a new one using (var newContents = File.OpenRead(fileStream.Name)) { return(HashCalculator.Hash(newContents)); } }
public static string Hash(Stream stream) { using (SHA1CryptoServiceProvider cryptoServiceProvider = new SHA1CryptoServiceProvider()) return(HashCalculator.Sanitize(cryptoServiceProvider.ComputeHash(stream))); }
public static string Hash(string input) { using (SHA1CryptoServiceProvider cryptoServiceProvider = new SHA1CryptoServiceProvider()) return(HashCalculator.Sanitize(cryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(input)))); }