TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
MD5 Hashing and Verification
Banketeshvar Narayan
Nov 14
2015
Code
1.1
k
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
using
System.Security.Cryptography;
using
System.Text;..................................................................
static
string
GetMd5Hash(
string
textToHash)
{
MD5CryptoServiceProvider md5CryptoServiceProvider =
new
MD5CryptoServiceProvider();
byte
[] data = md5CryptoServiceProvider.ComputeHash(Encoding.Default.GetBytes(textToHash));
StringBuilder sbHashedCode =
new
StringBuilder();
for
(
int
i = 0; i < data.Length; i++)
{
sbHashedCode.Append(data[i].ToString(
"x2"
));
}
return
sbHashedCode.ToString();
}
static
bool
verifyMd5Hash(
string
plainText,
string
hashedValue)
{
return
StringComparer.OrdinalIgnoreCase.Compare(GetMd5Hash(plainText), hashedValue) == 0 ?
true
:
false
;
}
MD5 Hashing
C#
Verification