Encrypt string

Below is the simple string encryption logic to encrypt string in asp.net. Anybody can change the logic to make it different then the default asp.net encryption logic for security perpose.

Below is the code to Encrypt String

private string EncryptString(string Name, int EmployeeId)
{
	try
	{
		string Source;
		Source = "";
		Source = Name + Convert.ToString(EmployeeId);

		string strRet;
		string strSub;

		ArrayList arrOffsets = new ArrayList();
		int intCounter;
		int intMod;
		int intVal;
		int intNewVal;

		arrOffsets.Insert(0, 73);
		arrOffsets.Insert(1, 56);
		arrOffsets.Insert(2, 31);
		arrOffsets.Insert(3, 58);
		arrOffsets.Insert(4, 77);
		arrOffsets.Insert(5, 75);

		strRet = "";

		for (intCounter = 0; intCounter < Source.Length; intCounter++)
		{
			strSub = Source.Substring(intCounter, 1);
			intVal = (int)System.Text.Encoding.ASCII.GetBytes(strSub)[0];
			intMod = intCounter % arrOffsets.Count;
			intNewVal = intVal + Convert.ToInt32(arrOffsets[intMod]);
			intNewVal = intNewVal % 256;
			strRet = strRet + intNewVal.ToString("X2");
		}
		return strRet;
	}
	catch (Exception ex)
	{
	    return "";
	}
}

 

Leave a Reply