当前位置: 首页>>代码示例>>C#>>正文


C# CryptoStream.ReadAllBinary方法代码示例

本文整理汇总了C#中System.Security.Cryptography.CryptoStream.ReadAllBinary方法的典型用法代码示例。如果您正苦于以下问题:C# CryptoStream.ReadAllBinary方法的具体用法?C# CryptoStream.ReadAllBinary怎么用?C# CryptoStream.ReadAllBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.CryptoStream的用法示例。


在下文中一共展示了CryptoStream.ReadAllBinary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Decrypt

 public static byte[] Decrypt(this byte[] data,
                              DeriveBytes key,
                              SymmetricAlgorithm algorithmUsing = null,
                              string initialVector = "OFRna73m*aze01xY",
                              int keySize = 256)
 {
     if (data.IsNull())
         return null;
     algorithmUsing = algorithmUsing.NullCheck(() => new RijndaelManaged());
     Guard.NotEmpty(initialVector, "initialVector");
     using (DeriveBytes derivedPassword = key)
     {
         using (SymmetricAlgorithm symmetricKey = algorithmUsing)
         {
             symmetricKey.Mode = CipherMode.CBC;
             byte[] plainTextBytes;
             using (
                 ICryptoTransform decryptor = symmetricKey.CreateDecryptor(derivedPassword.GetBytes(keySize/8),
                                                                           initialVector.ToByteArray()))
             {
                 using (var memStream = new MemoryStream(data))
                 {
                     using (var cryptoStream = new CryptoStream(memStream, decryptor, CryptoStreamMode.Read))
                     {
                         plainTextBytes = cryptoStream.ReadAllBinary();
                     }
                 }
             }
             symmetricKey.Clear();
             return plainTextBytes;
         }
     }
 }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:33,代码来源:SymmetricExtensions.cs

示例2: Decrypt

 public static byte[] Decrypt(this byte[] Data,
     DeriveBytes Key,
     SymmetricAlgorithm AlgorithmUsing = null,
     string InitialVector = "OFRna73m*aze01xY",
     int KeySize = 256)
 {
     if (Data.IsNull())
         return null;
     AlgorithmUsing = AlgorithmUsing.NullCheck(()=>new RijndaelManaged());
     InitialVector.ThrowIfNullOrEmpty("InitialVector");
     using (DeriveBytes DerivedPassword = Key)
     {
         using (SymmetricAlgorithm SymmetricKey = AlgorithmUsing)
         {
             SymmetricKey.Mode = CipherMode.CBC;
             byte[] PlainTextBytes = null;
             using (ICryptoTransform Decryptor = SymmetricKey.CreateDecryptor(DerivedPassword.GetBytes(KeySize / 8), InitialVector.ToByteArray()))
             {
                 using (MemoryStream MemStream = new MemoryStream(Data))
                 {
                     using (CryptoStream CryptoStream = new CryptoStream(MemStream, Decryptor, CryptoStreamMode.Read))
                     {
                         PlainTextBytes = CryptoStream.ReadAllBinary();
                     }
                 }
             }
             SymmetricKey.Clear();
             return PlainTextBytes;
         }
     }
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:31,代码来源:SymmetricExtensions.cs

示例3: Decrypt

 /// <summary>
 /// Decrypts a byte array
 /// </summary>
 /// <param name="Data">Data to be decrypted</param>
 /// <param name="Key">Password to decrypt with</param>
 /// <param name="Algorithm">Algorithm to use for decryption</param>
 /// <param name="InitialVector">Needs to be 16 ASCII characters long</param>
 /// <param name="KeySize">
 /// Can be 64 (DES only), 128 (AES), 192 (AES and Triple DES), or 256 (AES)
 /// </param>
 /// <returns>A decrypted byte array</returns>
 public byte[] Decrypt(byte[] Data, DeriveBytes Key, string Algorithm = "AES", string InitialVector = "OFRna73m*aze01xY", int KeySize = 256)
 {
     if (string.IsNullOrEmpty(InitialVector))
         throw new ArgumentNullException(nameof(InitialVector));
     if (Data == null)
         return null;
     using (SymmetricAlgorithm SymmetricKey = GetProvider(Algorithm))
     {
         byte[] PlainTextBytes = new byte[0];
         if (SymmetricKey != null)
         {
             SymmetricKey.Mode = CipherMode.CBC;
             using (ICryptoTransform Decryptor = SymmetricKey.CreateDecryptor(Key.GetBytes(KeySize / 8), InitialVector.ToByteArray()))
             {
                 using (MemoryStream MemStream = new MemoryStream(Data))
                 {
                     using (CryptoStream CryptoStream = new CryptoStream(MemStream, Decryptor, CryptoStreamMode.Read))
                     {
                         PlainTextBytes = CryptoStream.ReadAllBinary();
                     }
                 }
             }
             SymmetricKey.Clear();
         }
         return PlainTextBytes;
     }
 }
开发者ID:modulexcite,项目名称:Craig-s-Utility-Library,代码行数:38,代码来源:SymmetricBase.cs


注:本文中的System.Security.Cryptography.CryptoStream.ReadAllBinary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。