tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

SHA1 in a trice

8 Jun 2009 1 mins .NET, Cryptography, LINQ

Having girls/womans in a dev team is always fun. Yes, you have to wash your body more than every Visual Studio release. 😃 But girls have also different way of looking at the problem. I had this experience in a training last week. There’s one girl in dev team. While showing how to work with Cryptography namespace I was creating simple method for SHA1 hash. Saying, that’s pretty easy to create SHA1 hash in a couple of lines I got a question (yes, from the girl 😉), whether it’s possible to do it in one row, to make code more compact and show that’s double pretty easy. And it really is:

label1.Text = string.Join(string.Empty, new SHA1Managed().ComputeHash(Encoding.Unicode.GetBytes(textBox1.Text)).Select(_ => _.ToString()).ToArray());

It’s not the most readable code, but as a helper function somewhere … 😃

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.