What's Here?
- Members: 98,764
- Replies: 387,050
- Topics: 58,105
- Snippets: 2,024
- Tutorials: 546
- Total Online: 1,038
- Members: 41
- Guests: 997
Who's Online?
|
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: 457 |
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
|