SHA512
GetSha512Hash
// Generate the SHA512 hash
string hash = SecurityUtils.GetSha512Hash("Hello there!");
// Outputs "d0a1a241f4879b8fd8f9a2be55b004860f0e6f453ea8b42c8ad0e8cfc3721819dac6ec52f45b36044046b15cb8720874f701524aeac291921a865467781da456"
Console.WriteLine(hash);
With encoding:
// Generate the SHA512 hash
string hash = SecurityUtils.GetSha512Hash("Hello there!", Encoding.UTF8);
// Outputs "d0a1a241f4879b8fd8f9a2be55b004860f0e6f453ea8b42c8ad0e8cfc3721819dac6ec52f45b36044046b15cb8720874f701524aeac291921a865467781da456"
Console.WriteLine(hash);
With HEX format:
// Generate the SHA512 hash
string hash = SecurityUtils.GetSha512Hash("Hello there!", HexFormat.UpperCase));
// Outputs "D0A1A241F4879B8FD8F9A2BE55B004860F0E6F453EA8B42C8AD0E8CFC3721819DAC6EC52F45B36044046B15CB8720874F701524AEAC291921A865467781DA456"
Console.WriteLine(hash);
With HEX format and encoding:
// Generate the SHA512 hash
string hash = SecurityUtils.GetSha512Hash("Hello there!", HexFormat.UpperCase, Encoding.UTF8));
// Outputs "D0A1A241F4879B8FD8F9A2BE55B004860F0E6F453EA8B42C8AD0E8CFC3721819DAC6EC52F45B36044046B15CB8720874F701524AEAC291921A865467781DA456"
Console.WriteLine(hash);
GetSha512HashFromFile
// Generate the SHA256 hash
Guid hash = SecurityUtils.GetSha512HashFromFile("c:/obi-wan.txt");
// Outputs "d0a1a241f4879b8fd8f9a2be55b004860f0e6f453ea8b42c8ad0e8cfc3721819dac6ec52f45b36044046b15cb8720874f701524aeac291921a865467781da456"
Console.WriteLine(hash);
The GetSha512hashFromFile
method currently doesn't allow specifying the desired HEX format. As the file is read from disk, a method overload taking an encoding also isn't available.