| public string DESEncrypt(string strSource) { return DESEncrypt(strSource, DESKey); } public string DESEncrypt(string strSource,byte[] key) { SymmetricAlgorithm sa = Rijndael.Create(); sa.Key = key; sa.Mode= CipherMode.ECB; sa.Padding = PaddingMode.Zeros; MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, sa.CreateEncryptor(), CryptoStreamMode.Write); byte[] byt = Encoding.Unicode.GetBytes(strSource); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Convert.ToBase64String(ms.ToArray()); } /// <summary> /// DES解密 /// </summary> /// <param name="strSource">待解密的字串</param> /// <param name="key">32位Key值</param> /// <returns>解密后的字符串</returns> public string DESDecrypt(string strSource) { return DESDecrypt(strSource, DESKey); } public string DESDecrypt(string strSource,byte[] key) { SymmetricAlgorithm sa = Rijndael.Create(); sa.Key = key; sa.Mode = CipherMode.ECB; sa.Padding = PaddingMode.Zeros; ICryptoTransform ct = sa.CreateDecryptor(); byte[] byt = Convert.FromBase64String(strSource); MemoryStream ms = new MemoryStream(byt); CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Read); StreamReader sr = new StreamReader(cs, Encoding.Unicode); return sr.ReadToEnd(); }
|
| 共2页: 上一页 [1] 2 下一页 |
评论加载中…