diff --git a/README.md b/README.md index 501ede6..93b855b 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,59 @@ # acryptohashnet A pure c# implementation of well-known cryptographic hash functions for .Net Framework, .Net Core, Mono and other .Net Standard 2.1 compatible platforms. -Originally project was developed between 2006-2009 as an open source project and was hosted on SourceForge: https://sourceforge.net/projects/acryptohashnet/. - # Features * Pure managed implementations, * Implements System.Security.Cryptography.HashAlgorithm, * Fast and low memory footprints (less GC) -# Sample +# Usage samples + +## MD5 of file +``` csharp +using System; +using System.IO; +using System.Linq; + +static class Program +{ + static void Main(string[] args) + { + var hashAlgorithm = new acryptohashnet.MD5(); + + using(var stream = File.OpenRead(@"C:\Windows\System32\explorer.exe")) + { + var hashBytes = hashAlgorithm.ComputeHash(stream); + Console.WriteLine("Hash: {0}", hashBytes.ToHexString()); + } + } + + static string ToHexString(this byte[] input) => string.Join("", input.Select(x => x.ToString("x2"))); +} +``` + +## SHA512 of string ``` csharp -var hashAlgorithm = new acryptohashnet.SHA512(); -var hashBytes = hashAlgorithm.ComputeHash( - File.ReadAllBytes("file.txt") -); -Console.WriteLine("Hash: {0}", string.Join("", hashBytes.Select(x => x.ToString("x2")))) +using System; +using System.Linq; +using System.Text; + +static class Program +{ + static void Main(string[] args) + { + var hashAlgorithm = new acryptohashnet.SHA512(); + var hashBytes = hashAlgorithm.ComputeHash("message digest".ToUtf8Bytes()); + Console.WriteLine("Hash: {0}", hashBytes.ToHexString()); + } + + static byte[] ToUtf8Bytes(this string input) => Encoding.UTF8.GetBytes(input); + static string ToHexString(this byte[] input) => string.Join("", input.Select(x => x.ToString("x2"))); +} ``` # MD Family -All functions designed and specified by [Ron Rivest](https://en.wikipedia.org/wiki/Ron_Rivest). +All functions designed and specified by [Ron Rivest](https://en.wikipedia.org/wiki/Ron_Rivest). * MD2, specification: [RFC 1319](docs/rfc1319.txt). * MD4, specification: [RFC 1320](docs/rfc1320.txt). * MD5, specification: [RFC 1321](docs/rfc1320.txt). @@ -55,3 +89,6 @@ Designed and specified by [Ralph C. Merkle](https://en.wikipedia.org/wiki/Ralph_ Designed and specified by [Ross Anderson](https://en.wikipedia.org/wiki/Ross_J._Anderson) and [Eli Biham](https://en.wikipedia.org/wiki/Eli_Biham). +# See also +Originally project was developed between 2006-2009 as an open source project and was hosted on SourceForge: https://sourceforge.net/projects/acryptohashnet/. +