我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

流扩展: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://shouzuofang.com/article/esogg.html

其他资讯