What's Here?
- Members: 103,035
- Replies: 397,391
- Topics: 60,063
- Snippets: 2,113
- Tutorials: 587
- Total Online: 1,457
- Members: 60
- Guests: 1,397
Who's Online?
|
Welcome to Dream.In.Code |
|
|
Getting C# Help is Easy!
Join 103,035 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,457 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
This is a snippet I use for applying a one way hash utilizing the SHA1CryptoServiceProvider class in .Net. I use Encoding.Unicode.GetBytes() so it will be compatible with systems already using the CAPICOM version. The CAPICOM views all input as UNICODE not text
|
Submitted By: PsychoCoder
|
|
Rating:
 
|
|
Views: 547 |
Language: C#
|
|
Last Modified: May 12, 2008 |
|
Instructions: Need a reference to the System.Security.Cryptography and System.Web.Security Namespaces |
Snippet
//Namespace Reference
using System.Security.Cryptography;
using System.Web.Security;
/// <summary>
/// method to hash the users password. To match the CAPICOM hash
/// we convert the string to UNICODE first
/// </summary>
/// <returns></returns>
public string HashString(string str)
{
//create our SHA1 provider
SHA1 sha = new SHA1CryptoServiceProvider ();
string hashedValue = string.Empty;
//hash the data
byte[] hashedData = sha.ComputeHash(Encoding.Unicode.GetBytes(str));
//loop through each byte in the byte array
foreach (byte b in hashedData)
{
//convert each byte and append
hashedValue += String.Format("{0,2:X2}", b);
}
//return the hashed value
return hashedValue;
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|