//链接流加密 public void jiami3() { using ( SymmetricAlgorithm algorihtm = Rijndael.Create()) using (ICryptoTransform encryptor = algorihtm.CreateEncryptor (key, iv)) using (Stream f = File.Create("seruous.bin")) using (Stream c = new CryptoStream(f, encryptor, CryptoStreamMode.Write)) using (Stream d = new DeflateStream(c, CompressionMode.Compress)) using (StreamWriter w = new StreamWriter(d)) w.WriteLine("hello world"); } //链接流解密 public void jiemi3() { using (SymmetricAlgorithm algorithm = Rijndael.Create()) using (ICryptoTransform decryptor = algorithm.CreateDecryptor(key, iv)) using (Stream f = File.OpenRead("seruous.bin")) using (Stream c = new CryptoStream(f, decryptor, CryptoStreamMode.Read)) using (Stream d = new DeflateStream(c, CompressionMode.Decompress)) using (StreamReader r = new StreamReader(d)) Console.WriteLine(r.ReadLine()); }