How can I get SHA1 hash
in C# equivalent to produced by site http://www.sha1-online.com/
my sample string is
"20150819100015.test.1002-4-2015.978.GBP"
its hash string is
"caed6ade209e95ad973cce8def473f1e39e75c0b"
How can I get SHA1 hash
in C# equivalent to produced by site http://www.sha1-online.com/
my sample string is
"20150819100015.test.1002-4-2015.978.GBP"
its hash string is
"caed6ade209e95ad973cce8def473f1e39e75c0b"
NOTE: Updated my answer to be more specific to the question at hand upon reflection to comments.
Hashes are computer over byte arrays and since the byte array representation of a string is dependent upon the text encoding you're using it may not be possible to answer your question. This is because we do not know exactly what text encoding http://www.sha1-online.com uses.
I've made an assumption below that is using an UTF8 encoding, so whilst my sample code below will produce the hash your specified in the question with the corresponding input, it may not always produce the same hash as http://www.sha1-online.com for other given inputs.
The .NET Framework provides 3 class implementations of SHA1 namely SHA1Cng, SHA1CryptoServiceProvider and SHA1Managed.
The main difference between these implementations is dicussed here Which one to use: Managed vs. NonManaged hashing algorithms, but I have used to SHA1Managed in the code snippet below as it's implemented entirely in managed code and so whilst slower, should potentially be more portable to different platforms.
The output of a hash is also an array of bytes and so to turn the hash into a text representation I have converted the bytes to their hexadecimal representation and concatenated them as this appears to be the representation that http://www.sha1-online.com chooses to use.
static void Main(string[] args)
{
var sha1 = new System.Security.Cryptography.SHA1Managed();
var plaintextBytes = Encoding.UTF8.GetBytes("20150819100015.test.1002-4-2015.978.GBP");
var hashBytes = sha1.ComputeHash(plaintextBytes);
var sb = new StringBuilder();
foreach (var hashByte in hashBytes)
{
sb.AppendFormat("{0:x2}", hashByte);
}
var hashString = sb.ToString();
}