Strong Encryption and Decryption Class For Asp.Net


Hello,
I Have Found Strong Encryption and Decryption Class For encrypt and Decrypt login and Password in .Net Application during googleing.
Strong Encryption and Decryption Class For Asp.Net

For Decryption

public string Decry(string TextToBeDecrypted)
{
RijndaelManaged RijndaelCipher = new RijndaelManaged();
string Password = "CSC";
string DecryptedData;
try
{
byte[] EncryptedData = Convert.FromBase64String(TextToBeDecrypted);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
//Making of the key for decryption
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
//Creates a symmetric Rijndael decryptor object.
ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream(EncryptedData);
//Defines the cryptographics stream for decryption.THe stream contains decrpted data
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
byte[] PlainText = new byte[EncryptedData.Length];
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
memoryStream.Close();
cryptoStream.Close();
//Converting to string
DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
}
catch
{
DecryptedData = TextToBeDecrypted;
}
return DecryptedData;
}


For Encryption
public string Encry(string TextToBeEncrypted)
{
RijndaelManaged RijndaelCipher = new RijndaelManaged();
string Password = "CSC";
byte[] PlainText = System.Text.Encoding.Unicode.GetBytes(TextToBeEncrypted);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
//Creates a symmetric encryptor object.
ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream();
//Defines a stream that links data streams to cryptographic transformations
CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);
cryptoStream.Write(PlainText, 0, PlainText.Length);
//Writes the final state and clears the buffer
cryptoStream.FlushFinalBlock();
byte[] CipherBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string EncryptedData = Convert.ToBase64String(CipherBytes);
return EncryptedData;
}



Prev Post                    All Post                           Next Post

Posted in |

3 comments:

  1. Anonymous Says:

    Hi Ketan

    Anish Here,

    hey when user is logging into the website, i want to fetch his computer ipaddress(ipaddress of client machine that is connected to server), then how can i do this..??

  2. Anonymous Says:

    Hi Ketan
    Anish Here,

    Can we connect asp.net 2.0/3.0 with SAP System..?

  3. Ranga Rajesh Kumar Says:

    for 1024 bit encryption http://aspnettutorialonline.blogspot.com/2012/05/encryption-and-decryption-in-aspnet.html

Post a Comment