Forum Index

It appears you have not yet registered with our community which limits what you can do & see. It's Free To register, please click here.





Software Software related issues

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2007, 04:57 AM
hanusoftware hanusoftware is offline
Junior Member
 
Join Date: Jun 2007
Posts: 1
Code to encrypt the Password or any string

/// <summary>

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

/// And return the Encrypted String

/// </summary>

/// <param name="str"></param>

/// <returns></returns>

public string encryptPassword(string strText)

{

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

}

/// <summary>

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

/// And return the decrypted string

/// </summary>

/// <param name="str"></param>

/// <returns></returns>

public string decryptPassword(string str)

{

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

}

/// <summary>

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

/// passed string

/// </summary>

/// <param name="strText"></param>

/// <param name="strEncrypt"></param>

/// <returns></returns>

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.Subs tring(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;

}

}

/// <summary>

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

/// </summary>

/// <param name="strText"></param>

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

/// <param name="strEncrypt"></param>

/// <returns></returns>

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.Subs tring(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
Reply With Quote
Posted


  #2  
Old 01-11-2008, 12:54 AM
caymenturbo caymenturbo is offline
Junior Member
 
Join Date: Jan 2008
Posts: 3
about encrypt, what i only remember is: abcde->(character+n)->xxxxx

sorry for the joke.
Reply With Quote
Reply

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump



All times are GMT -5. The time now is 07:58 PM.


Firefox 2