Reply
encrypt solution for c#
Old 04-17-2009, 12:48 PM encrypt solution for c#
Average Talker

Posts: 21
Trades: 0
Actually i want encrypt my password field in registration form. anybody help me..
thanks in advance..
__________________
for best web designig and hosting
visit http://www.prosysdevelopers.com
Rams is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 04-19-2009, 11:02 PM Re: encrypt solution for c#
Skilled Talker

Posts: 69
Trades: 0
In the web.config in configuration put the following:

Use random characters for the encryption string: something like: "kljasLKDKJH)&&^#WQ##@"
<appSettings>
<add key="EncryptionString" value="Random Characters for Encryption" />
</appSettings>


public static string Encrypt(string toEncrypt)
{
byte[] keyArray;
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);
AppSettingsReader appSettings = new AppSettingsReader();

string key = appSettings.GetValue("EncryptionString", typeof(string)).ToString();

MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key ));

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}

public static string Decrypt(string toDecrypt)
{
byte[] keyArray;
byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);
AppSettingsReader appSettings = new AppSettingsReader();

string key = appSettings.GetValue("EncryptionString", typeof(string)).ToString();


MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key ));

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

return UTF8Encoding.UTF8.GetString(resultArray);
}
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 04-22-2009, 09:28 AM Re: encrypt solution for c#
Average Talker

Posts: 21
Trades: 0
stbuchok!

Thanks a lot for your kind reply!
i used it, i using string value instead of EncryptionString in web.config file

any way. very useful this.
thanx
__________________
for best web designig and hosting
visit http://www.prosysdevelopers.com
Rams is offline
Reply With Quote
View Public Profile
 
Old 06-09-2009, 09:01 AM Re: encrypt solution for c#
Skilled Talker

Posts: 69
Trades: 0
Just for the record anyone who sees this code may want to read this. I feel like a jack@ss cause I'm also one of these guys that just copied this and didn't try to fully understand what it was doing.

http://www.codinghorror.com/blog/archives/001267.html

I'm not going to tell you what is wrong with the code, you need to read this and find out for yourself.
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 06-12-2009, 11:43 AM Re: encrypt solution for c#
Super Talker

Posts: 101
Trades: 0
Rather than encrypting the user password, you should use the MD5 hash of the password. MD5 is the most secured password saving technique as it is impossible to reverse engineer the MD5 hash to its original string.

You may refer this to convert any string into the MD5 hash, http://forums.exaspring.com/microsof...using-c-sharp/
__________________
AccuWebHosting.Com - Windows Hosting Expert
ASP.NET 3.5 | SQL 2005 Database | US Based Hosting Company | 24 X 7 Support | Daily Backups | Uptime Guarantee | Affiliates - $50 Per Sale
| Website Hosting
twhdir is offline
Reply With Quote
View Public Profile
 
Old 06-15-2009, 08:37 AM Re: encrypt solution for c#
Skilled Talker

Posts: 69
Trades: 0
twhdir if you look at the code it is using MD5CryptoServiceProvider().
stbuchok is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to encrypt solution for c#
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.12635 seconds with 13 queries