Base64 Encoding/Decoding - 예제

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("암호화");
			Console.WriteLine("=================================");
			string key = string.Empty;
			Console.Write("ID: ");
			key = Console.ReadLine();

			if (string.IsNullOrEmpty(key))
				key = "jincaesar";

			string temp = string.Empty;
			char ch = 'a';
			for (int i = 0; i < key.Length; i++)
			{
				temp += key.Insert(i + 1, Convert.ToString(ch++)).Substring(i, 2);
			}

			Console.WriteLine(temp);

			string value = Convert.ToBase64String(Encoding.GetEncoding("UTF-8").GetBytes(temp));
			Console.WriteLine(value);

			Console.ReadKey();
			Console.WriteLine("");
			Console.WriteLine("복호화");
			Console.WriteLine("=================================");

			value = Encoding.GetEncoding("UTF-8").GetString(Convert.FromBase64String(value));
			temp = string.Empty;
			for (int i = 0; i < value.Length; i++)
			{
				if (i % 2 == 0)
					temp += value.Substring(i, 1);
			}
			Console.WriteLine(temp);

			Console.ReadKey();
		}
	}
}

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by jincaesar

2015/03/23 11:41 2015/03/23 11:41
Response
No Trackback , No Comment
RSS :
http://jincaesar.maru.net/tc/rss/response/143

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

« Previous : 1 : 2 : 3 : 4 : 5 : 6 : ... 70 : Next »