Program: szyfrujący tekst przez SHA-1.
Jak w opisie.
Kompilator: Microsoft Visual Studio
Kod programu:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace SHA_1
{
class Program
{
static void Main(string[] args)
{
string inputstring = "Hello World!";
using (SHA1 SHA1Hash = SHA1.Create())
{
string hash = GetHashString(inputstring);
Console.WriteLine("Wynik haszowania SHA1 tekstu " + inputstring + " jest: " + hash);
Console.ReadKey();
}
}
public static byte[] GetHash(string inputstring)
{
HashAlgorithm algorithm = SHA1.Create();
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputstring));
}
public static string GetHashString(string inputstring)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in GetHash(inputstring))
sb.Append(b.ToString("x2"));
return sb.ToString();
}
}
} Słowniczek pojęć:
Rodzina powiązanych ze sobą kryptograficznych funkcji skrótu zaprojektowanych przez NSA (National Security Agency) i publikowanych przez National Institute of Standards and Technology.
Pierwszy z nich opublikowany w 1993 oficjalnie nazwany SHA (nieoficjalnie, żeby nie pomylić z następcami określany jako SHA-0).
SHA-1 opublikowany został w 1995 i całkowicie zastąpił wycofanego (ze względu na nieujawnione oficjalnie wady) z użytku SHA-0. SHA-0 i SHA-1 tworzą 160-bitowy skrót z wiadomości o maksymalnym rozmiarze 264 bitów i jest oparty na podobnych zasadach co MD5. Algorytm SHA-1 nie powinien być używany w nowych aplikacjach.