加密解密

   #region 字符串加密解密         public static byte[] MakeMD5(byte[] original)         {             MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();             byte[] keyhash = hashmd5.ComputeHash(original);             hashmd5 = null;             return keyhash;         }         public static byte[] Encrypt(byte[] original, byte[] key)         {             TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();             des.Key = MakeMD5(key);             des.Mode = CipherMode.ECB;             return des.CreateEncryptor().TransformFinalBlock(original, 0, original.Length);         }         public static byte[] Decrypt(byte[] encrypted, byte[] key)         {             TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();             des.Key = MakeMD5(key);             des.Mode = CipherMode.ECB;

            return des.CreateDecryptor().TransformFinalBlock(encrypted, 0, encrypted.Length);         }         public static byte[] Encrypt(byte[] original)         {             byte[] key = System.Text.Encoding.Default.GetBytes("JASONHEUNG");             return Encrypt(original, key);         }         public static byte[] Decrypt(byte[] encrypted)         {             byte[] key = System.Text.Encoding.Default.GetBytes("JASONHEUNG");             return Decrypt(encrypted, key);         }         public  string Encrypt(string original)         {             try             {                 return Encrypt(original, "JASONHEUNG");             }             catch (Exception ee)             {                 return ee.ToString();             }         }         public  string Decrypt(string original)         {             return Decrypt(original, "JASONHEUNG", System.Text.Encoding.Default);         }         public  string Decrypt(string original, string key)         {             return Decrypt(original, key, System.Text.Encoding.Default);         }         public static string Decrypt(string original, Encoding encoding)         {             return Decrypt(original, "JASONHEUNG", encoding);         }         public  string Encrypt(string original, string key)//使用指定密匙加密字符串         {             try             {                 byte[] buff = System.Text.Encoding.Default.GetBytes(original);                 byte[] kb = System.Text.Encoding.Default.GetBytes(key);                 return Convert.ToBase64String(Encrypt(buff, kb));             }             catch (Exception ee)             {                 return ee.ToString();             }         }         public static string Decrypt(string encrypted, string key, Encoding encoding)//使用指定密匙解密字符串         {             try             {                 byte[] buff = Convert.FromBase64String(encrypted);                 byte[] kb = System.Text.Encoding.Default.GetBytes(key);                 return encoding.GetString(Decrypt(buff, kb));             }             catch             {                 return "";             }         }         #endregion

注: 登录地址:https://dev.windowsphone.com/zh-cn     邮箱对应的Live ID:biz.whuan@hotmail.com     Live ID密码:mappn123     1)机锋专有账号,请不要随便更改账户的注册信息和内容。如发现随意变更,将取消手机奖励。     2)产品有提交和状态更新,请及时反馈数据。项目结束时间大约在5.7号左右,请注意开发进度。        

posted @ 2013-08-24 13:34  lanmiao  阅读(277)  评论(0编辑  收藏  举报