/// <summary> /// 解密方法 /// </summary> /// <param name="Source">待解密的串</param> /// <returns>经过解密的串</returns> public string DecryptoByte(string Source) { try { if (EncryptString.DiscryptSilmoonBinary(Source) == "") { return(""); } byte[] bytIn = Convert.FromBase64String(EncryptString.DiscryptSilmoonBinary(Source)); MemoryStream ms = new MemoryStream(bytIn, 0, bytIn.Length); mobjCryptoService.Key = GetLegalKey(); mobjCryptoService.IV = GetLegalIV(); ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor(); CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read); StreamReader sr = new StreamReader(cs); return(sr.ReadToEnd()); } catch { return(""); } }
/// <summary> /// 加密方法 /// </summary> /// <param name="Source">待加密的串</param> /// <returns>经过加密的串</returns> public string EncryptoByte(string Source) { if (Source == "") { return(""); } byte[] bytIn = UTF8Encoding.UTF8.GetBytes(Source); MemoryStream ms = new MemoryStream(); mobjCryptoService.Key = GetLegalKey(); mobjCryptoService.IV = GetLegalIV(); ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor(); CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write); cs.Write(bytIn, 0, bytIn.Length); cs.FlushFinalBlock(); ms.Close(); byte[] bytOut = ms.ToArray(); return(EncryptString.EncryptSilmoonBinary(Convert.ToBase64String(bytOut))); }