InstantASP Community Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



Code to encrypt the Password or any... Expand / Collapse
Author
Message
Posted 10/07/2007 05:17:19
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 15/10/2008 14:23:56
Posts: 4, Visits: 6
///

/// Thsi method retrieve the string to encrypt from the Presentation Layer

/// And return the Encrypted String

///


///

///

public string encryptPassword(string strText)

{

return Encrypt(strText, "&%#@?,:*");

}

///

/// This method retrieve the encrypted string to decrypt from the Presentation Layer

/// And return the decrypted string

///


///

///

public string decryptPassword(string str)

{

return Decrypt(str, "&%#@?,:*");

}

///

/// This method has been used to get the Encrypetd string for the

/// passed string

///


///

///

///

private string Encrypt(string strText, string strEncrypt)

{

byte[] byKey = new byte[20];

byte[] dv ={ 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

try

{

byKey = System.Text.Encoding.UTF8.GetBytes(strEncrypt.Substring(0, 8));

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

byte[] inputArray = System.Text.Encoding.UTF8.GetBytes(strText);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, dv), CryptoStreamMode.Write);

cs.Write(inputArray, 0, inputArray.Length);

cs.FlushFinalBlock();

return Convert.ToBase64String(ms.ToArray());

}

catch (Exception ex)

{

throw ex;

}

}

///

/// This method has been used to Decrypt the Encrypted String

///


///

/// http://www.hanusoftware.com

///

///

private string Decrypt(string strText, string strEncrypt)

{

byte[] bKey = new byte[20];

byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

try

{

bKey = System.Text.Encoding.UTF8.GetBytes(strEncrypt.Substring(0, 8));

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

Byte[] inputByteArray = inputByteArray = Convert.FromBase64String(strText);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(bKey, IV), CryptoStreamMode.Write);

cs.Write(inputByteArray, 0, inputByteArray.Length);

cs.FlushFinalBlock();

System.Text.Encoding encoding = System.Text.Encoding.UTF8;

return encoding.GetString(ms.ToArray());

}

catch (Exception ex)

{

throw ex;

}

}
Software Development India


Offshore Software Development Company India, Software Development India
Post #13033
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ryan Healey, Mark Christianson, Bare, James Trott

Permissions Expand / Collapse

All times are GMT, Time now is 1:13pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.094. 10 queries. Compression Disabled.
Home | Products | Purchase | Support | Company | Contact Us
Privacy Statement | © 1999-2007 InstantASP Limited. All Rights Reserved.