/// <summary>
/// 쿠키 Encode
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string CookieEncode(string str)
{
string code = string.Empty;
for (int i = 0; i < str.Length; i++)
{
string nstr = str.Substring(i, 1);
int ascnum = Convert.ToInt32(Convert.ToChar(nstr));
code += String.Format("{0:X}", ascnum);
}
return code;
}
/// <summary>
/// 쿠키 Decode
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static string CookieDecode(string code)
{
string rst = string.Empty;
for (int i = 0; i < code.Length; i += 2)
{
string nstr = code.Substring(i, 2);
int n = Convert.ToInt32(nstr, 16);
if (n > Convert.ToInt32("7F", 16))
{
nstr = code.Substring(i, 4);
n = Convert.ToInt32(nstr, 16);
}
rst += (char)n;
}
return rst;
}
/// 쿠키 Encode
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string CookieEncode(string str)
{
string code = string.Empty;
for (int i = 0; i < str.Length; i++)
{
string nstr = str.Substring(i, 1);
int ascnum = Convert.ToInt32(Convert.ToChar(nstr));
code += String.Format("{0:X}", ascnum);
}
return code;
}
/// <summary>
/// 쿠키 Decode
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static string CookieDecode(string code)
{
string rst = string.Empty;
for (int i = 0; i < code.Length; i += 2)
{
string nstr = code.Substring(i, 2);
int n = Convert.ToInt32(nstr, 16);
if (n > Convert.ToInt32("7F", 16))
{
nstr = code.Substring(i, 4);
n = Convert.ToInt32(nstr, 16);
}
rst += (char)n;
}
return rst;
}
'ASP.NET' 카테고리의 다른 글
Html 태그 없애기 (0) | 2015.05.28 |
---|---|
지정한 길이만큼 랜덤으로 문자열를 만들어 반환한다 (0) | 2015.05.28 |
문자열을 바이트 단위로 잘라낸다.한글 2바이트, 영문 1바이트 (0) | 2015.05.28 |
다중 업로드 파일 클래스를 맹글어 보자 (0) | 2015.05.27 |
AutoCompleteExtender 컨트롤을 이용한 자동완성 기능 구현 (0) | 2015.05.27 |