Задатак
Као и у претходном примеру, креирајте конзолне апликације које ће израчунавати хеш вредности помоћу алгоритама SHA1, SHA256, SHA384 и SHA512 за задате стрингове (UTF8).
Решење
using System;
using System.Security.Cryptography;
using System.Text;
namespace sha1_hes
{
internal class Program
{
private static void Main()
{
Console.Write("Unesite tekst: ");
string tekst = Console.ReadLine();
SHA1 sha1hes = SHA1.Create();
byte[] ulazniBajtovi = Encoding.UTF8.GetBytes(tekst);
byte[] izlazniBajtovi = sha1hes.ComputeHash(ulazniBajtovi);
string hesVrednost = BitConverter.ToString(izlazniBajtovi).Replace("-", "");
Console.WriteLine("SHA1: " + hesVrednost);
}
}
}
Напомена
Поступак је исти за остале алгоритме само се користе класе SHA256, SHA384 и SHA512 уместо класе SHA1.
Тест пример
Unesite tekst: Heširaj mi ovaj tekst!
SHA1: 62DA2D2AB84BACC2D656189C85008832634A8358
Документација
SHA1 Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha1
SHA1Cng Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha1cng
SHA1CryptoServiceProvider Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha1cryptoserviceprovider
SHA1Managed Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha1managed
SHA256 Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha256
SHA256Cng Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha256cng
SHA256CryptoServiceProvider Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha256cryptoserviceprovider
SHA256Managed Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha256managed
SHA384 Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha384
SHA384Cng Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha384cng
SHA384CryptoServiceProvider Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha384cryptoserviceprovider
SHA384Managed Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha384managed
SHA512 Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha512
SHA512Cng Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha512cng
SHA512CryptoServiceProvider Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha512cryptoserviceprovider
SHA512Managed Class: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha512managed