using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;
namespace edu.jhu.Cas.Util{
	public class Encryptor{
	
		private Byte[] key = {11, 2, 3, 4, 5, 6, 55, 10, 9, 10, 11, 33, 13, 14, 15, 16, 17, 18, 32, 20, 21, 8, 23, 24};
		private Byte[] initVector = {32, 110, 68, 26, 69, 178, 200, 19};
		
		private TripleDESCryptoServiceProvider des =new TripleDESCryptoServiceProvider();
		
		public byte[] Transform(byte[] input,ICryptoTransform cryptoTransform){
			MemoryStream stream = new MemoryStream();
			CryptoStream cryptoStream = new CryptoStream(stream, cryptoTransform,CryptoStreamMode.Write);
			cryptoStream.Write(input, 0, input.Length);
			cryptoStream.FlushFinalBlock();
			return stream.ToArray();
			//return Convert.ToBase64String(stream.ToArray());
		}
		public byte[] TripleDESEncrypt(string text){
			return Transform(Encoding.Default.GetBytes(text), des.CreateEncryptor(key, initVector));
		}
		public string TripleDESDecrypt(byte[] encrypted){
			return Encoding.Default.GetString(Transform(encrypted,des.CreateDecryptor(key, initVector)));
		}
		public string Byte2String(byte[] a){
			return Encoding.Default.GetString(a);
		}
		public static string MD52Base64Encrypt(string text){
			MD5 md5 = new MD5CryptoServiceProvider();
			MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(text));
			byte[] rst = md5.ComputeHash(stream);
			stream.Close();
			return Convert.ToBase64String(rst);
		
		}
		
	}
}