static byte[] bytes = ASCIIEncoding.ASCII.GetBytes("ZeroCool");
Console.WriteLine("Original String: ");
string originalString = Console.ReadLine();
string encryptedString = Encrypt(originalString);
Console.WriteLine("\nEncrypt Result: {0}", encryptedString);
Console.WriteLine("Decrypt Result: {0}", Decrypt(cryptedString));
public static string Encrypt(string originalString)
{
if (String.IsNullOrEmpty(originalString))
{
throw new ArgumentNullException "The string which needs to be encrypted can not be null.");
}
var cryptoProvider = new DESCryptoServiceProvider();
var memoryStream = new MemoryStream();
var cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes),
CryptoStreamMode.Write);
var writer = new StreamWriter(cryptoStream);
writer.Write(originalString);
writer.Flush();
cryptoStream.FlushFinalBlock();
writer.Flush();
return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
}
public static string Decrypt(string encryptedString)
{
if (String.IsNullOrEmpty(encryptedString))
{
throw new ArgumentNullException("The string which needs to be decrypted can not be null.");
}
var cryptoProvider = new DESCryptoServiceProvider();
var memoryStream = new MemoryStream(Convert.FromBase64String(cryptedString));
var cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes),
CryptoStreamMode.Read);
var reader = new StreamReader(cryptoStream);
return reader.ReadToEnd();
}
Mahesh Chilu...
Member
32 Points
117 Posts
password encryption and decryption in asp.net c#
Nov 06, 2012 03:07 AM|LINK
Hello please any one tell how to encryption and decryption in the web application.
heyitsme
Participant
1397 Points
503 Posts
Re: password encryption and decryption in asp.net c#
Nov 06, 2012 03:17 AM|LINK
you can refer this link
http://www.codeproject.com/Articles/463390/Password-Encryption-using-MD5-Hash-Algorithm-in-Cs
Mahesh Chilu...
Member
32 Points
117 Posts
Re: password encryption and decryption in asp.net c#
Nov 06, 2012 03:19 AM|LINK
I am using web application.
me_ritz
Star
9339 Points
1448 Posts
Re: password encryption and decryption in asp.net c#
Nov 06, 2012 03:22 AM|LINK
Gain some knowledge about cryptography -
http://www.codeproject.com/Articles/10154/NET-Encryption-Simplified
For password encryption-decryption -
http://www.aspdotnet-suresh.com/2010/12/introduction-here-i-will-explain-how-to_28.html
ramiramilu
All-Star
98033 Points
14516 Posts
Re: password encryption and decryption in asp.net c#
Nov 07, 2012 11:19 AM|LINK
you can do one way hash of passwords - http://www.adventuresindevelopment.com/2009/05/23/a-simple-way-to-hash-passwords-in-aspnet/
Thanks,
JumpStart
Saritha.S.R
Member
332 Points
140 Posts
Re: password encryption and decryption in asp.net c#
Nov 07, 2012 11:22 AM|LINK
Hi,
Take a look into the following:
http://www.c-sharpcorner.com/Blogs/9384/how-to-encrypt-or-decrypt-password-using-Asp-Net-with-C-Sharp.aspx
Thanks.
tarek yehia
Member
206 Points
50 Posts
Re: password encryption and decryption in asp.net c#
Nov 07, 2012 11:33 AM|LINK
The best way of encryption is by using hash md5 algorithm try the followin link :
http://4rapiddev.com/csharp/asp-net-c-create-md5-hash/
matifnadeem
Contributor
4964 Points
1154 Posts
Re: password encryption and decryption in asp.net c#
Nov 07, 2012 11:36 AM|LINK
Hi Mahesh Chiluka,
Use this code,
static byte[] bytes = ASCIIEncoding.ASCII.GetBytes("ZeroCool"); Console.WriteLine("Original String: "); string originalString = Console.ReadLine(); string encryptedString = Encrypt(originalString); Console.WriteLine("\nEncrypt Result: {0}", encryptedString); Console.WriteLine("Decrypt Result: {0}", Decrypt(cryptedString)); public static string Encrypt(string originalString) { if (String.IsNullOrEmpty(originalString)) { throw new ArgumentNullException "The string which needs to be encrypted can not be null."); } var cryptoProvider = new DESCryptoServiceProvider(); var memoryStream = new MemoryStream(); var cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write); var writer = new StreamWriter(cryptoStream); writer.Write(originalString); writer.Flush(); cryptoStream.FlushFinalBlock(); writer.Flush(); return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length); } public static string Decrypt(string encryptedString) { if (String.IsNullOrEmpty(encryptedString)) { throw new ArgumentNullException("The string which needs to be decrypted can not be null."); } var cryptoProvider = new DESCryptoServiceProvider(); var memoryStream = new MemoryStream(Convert.FromBase64String(cryptedString)); var cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read); var reader = new StreamReader(cryptoStream); return reader.ReadToEnd(); }Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
Umair Ghafoo...
Member
28 Points
44 Posts
Re: password encryption and decryption in asp.net c#
Feb 04, 2013 09:40 AM|LINK
@Atif. nice code