新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

流扩展:StreamExtensions-创新互联

10年积累的做网站、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有回民免费网站建设让你可以放心的选择与我们合作。>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.IO; namespace Beehive.CloudReader.Utility { /// /// Stream 扩展 /// public static class StreamExtensions { /// /// /// /// /// /// /// public static System.IO.Stream Encrypt(this System.IO.Stream stream, byte[] key) where Algorithm : SymmetricAlgorithm { var alg = Activator.CreateInstance(); PasswordDeriveBytes pdb= new PasswordDeriveBytes(key, null); alg.Key= pdb.GetBytes(alg.KeySize / 8); alg.GenerateIV(); alg.IV= pdb.GetBytes(alg.IV.Length); ICryptoTransform encryptor= alg.CreateEncryptor(); return new CryptoStream(stream, encryptor, CryptoStreamMode.Read); } /// /// /// /// /// /// /// public static System.IO.Stream Decrypt(this System.IO.Stream stream, byte[] key) where Algorithm : SymmetricAlgorithm { var alg = Activator.CreateInstance(); PasswordDeriveBytes pdb= new PasswordDeriveBytes(key, null); alg.Key= pdb.GetBytes(alg.KeySize / 8); alg.GenerateIV(); alg.IV= pdb.GetBytes(alg.IV.Length); ICryptoTransform encryptor= alg.CreateDecryptor(); return new CryptoStream(stream, encryptor, CryptoStreamMode.Read); } /// /// /// /// /// public static byte[] ToByteArray(this System.IO.Stream stream) { byte[] buffer = new byte[1000]; int readLength = 1; using (MemoryStream ms = new MemoryStream()) { while (readLength > 0) { readLength= stream.Read(buffer, 0, buffer.Length); if (readLength > 0) ms.Write(buffer,0, readLength); } return ms.ToArray(); } } } }
分享文章:流扩展:StreamExtensions-创新互联
网站地址:http://www.wjwzjz.com/article/esogg.html
在线咨询
服务热线
服务热线:028-86922220
TOP