Showing posts with label text hex text2Hex hex2Txt. Show all posts
Showing posts with label text hex text2Hex hex2Txt. Show all posts

Friday, August 22, 2008

txt2Hex hex2Txt

/ / JK - for psuedo-encrytping the user entered password to hex
public static string txt2Hex(string arg)
{
string retval = "";
try
{
foreach (char c in arg)
{
int tmp = c;
retval += String.Format("{0:x2}",
(uint)System.Convert.ToUInt32(tmp.ToString()));
}
}
catch (Exception ex)
{
LogUtil.logMeLogic ( "Error : txt2Hex : |" + arg + "| : " + ex.ToString(),
false )
return "-1";
}
return retval;
}

// JK - for decyrpting the psuedo-encrytped the user entered password from hex
public static string hex2Txt(string arg)
{
string retval = "";
try
{
if (arg.Length % 2 != 0)
{
throw new Exception();
}
while (arg.Length > 0)
{
retval += System.Convert.ToChar(System.Convert.ToUInt32(arg.Substring(0,
2), 16)).ToString();
arg = arg.Substring(2, arg.Length - 2);
}
}
catch (Exception ex)
{
LogUtil.logMeLogic ( "Error : txt2Hex : |" + arg + "| : " + ex.ToString(),
false )
return "-1";
}
return retval;
}
}

// Partial source: http://www.testingreflections.com/node/view/5635