This outlines .NET hashes.
Hashing and C# |
Code
First we create a folder named "hashing", and then go into that folder.We can create a Dotnet console project for .NET 8.0 with:
dotnet new console --framework net8.0
This produces a Csproject file of:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> </Project>
Some simple code is:
namespace Hashing { class Program { static void Main(string[] args) { string str="Hello"; if (args.Length >0) str=args[0]; try { byte[] s1= System.Security.Cryptography.MD5.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); byte[] s2 = System.Security.Cryptography.SHA1.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); byte[] s3 = System.Security.Cryptography.SHA256.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); byte[] s4 = System.Security.Cryptography.SHA384.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); byte[] s5 = System.Security.Cryptography.SHA512.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)); Console.WriteLine( "String: {0}",str); Console.WriteLine( "\nMD5 (Hex): " + BitConverter.ToString(s1).Replace("-","")); Console.WriteLine( "\nSHA1 (Hex): " + BitConverter.ToString(s2).Replace("-","")); Console.WriteLine( "\nSHA256 (Hex): " + BitConverter.ToString(s3).Replace("-","")); Console.WriteLine( "\nSHA384 (Hex): " + BitConverter.ToString(s4).Replace("-","")); Console.WriteLine( "\nsha512 (Hex): " + BitConverter.ToString(s5).Replace("-","")); } catch (Exception e) { Console.WriteLine("Error: {0}",e.Message); } } } }
A sample run is:
MD5 (Hex): 8B1A9953C4611296A827ABF8C47804D7 SHA1 (Hex): F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0 SHA256 (Hex): 185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969 SHA384 (Hex): 3519FE5AD2C596EFE3E276A6F351B8FC0B03DB861782490D45F7598EBD0AB5FD5520ED102F38C4A5EC834E98668035FC sha512 (Hex): 3615F80C9D293ED7402687F94B22D58E529B8CC7916F8FAC7FDDF7FBD5AF4CF777D3D795A7A00A16BF7E7F3FB9561EE9BAAE480DA9FE7A18769E71886B03F315
Presentation
Here is an outline: