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


C# CryptoStream.ReadByte方法代码示例

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


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

示例1: Decrypt

        public byte[] Decrypt(byte[] cipher, byte[] key, byte[] IV)
        {
            System.Collections.Generic.List<byte> bytes = new List<byte>();

            using (AesManaged _aesAlgorithm = new AesManaged())
            {
                _aesAlgorithm.Key = key;
                _aesAlgorithm.IV = IV;

                using (ICryptoTransform decryptor = _aesAlgorithm.CreateDecryptor(_aesAlgorithm.Key, _aesAlgorithm.IV))
                {
                    using (System.IO.MemoryStream str = new System.IO.MemoryStream(cipher))
                    {
                        using (CryptoStream crypto = new CryptoStream(str, decryptor, CryptoStreamMode.Read))
                        {
                            int b = crypto.ReadByte();

                            while (b > -1)
                            {
                                b = crypto.ReadByte();
                                bytes.Add((byte)b);
                            }
                        }
                    }
                    _aesAlgorithm.Clear();
                }
            }

            return bytes.ToArray();
        }
开发者ID:shovelheadfxe,项目名称:DevLab,代码行数:30,代码来源:CMS.cs

示例2: DecryptText

        public static string DecryptText(string encryptedText)
        {
            try
            {
                RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
                ICryptoTransform decryptor = rc2CSP.CreateDecryptor(Convert.FromBase64String(C_KEY), Convert.FromBase64String(C_IV));
                MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(encryptedText));
                CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
                List<Byte> bytes = new List<byte>();
                int b;
                do
                {
                    b = csDecrypt.ReadByte();
                    if (b != -1)
                    {
                        bytes.Add(Convert.ToByte(b));
                    }

                } while (b != -1);

                return Encoding.Unicode.GetString(bytes.ToArray());
            }
            catch (Exception)
            {
                return "";
            }
        }
开发者ID:wj88808886,项目名称:OSU_PrintingHelper_Windows,代码行数:27,代码来源:CredentialsManager.cs

示例3: DecryptFile

       public static void DecryptFile(string inputFile, string outputFile, string skey)
       {
           RijndaelManaged aes = new RijndaelManaged();

           try
           {
               byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);

               using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
               {
                   using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
                   {
                       using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateDecryptor(key, key), CryptoStreamMode.Read))
                       {
                           int data;

                           while ((data = cs.ReadByte()) != -1)
                           {
                               fsOut.WriteByte((byte)data);
                           }

                           aes.Clear();
                       }
                   }
               }

           }
           catch (Exception ex)
           {
               Console.WriteLine(ex.Message);
               aes.Clear();
           }
       }
开发者ID:samuraitruong,项目名称:comitdownloader,代码行数:33,代码来源:SecureHelper.cs

示例4: DecryptFile

		public static void DecryptFile(string inputFile, string outputFile, string password)
		{
			{
				var unicodeEncoding = new UnicodeEncoding();
				byte[] key = unicodeEncoding.GetBytes(FormatPassword(password));

				if (!File.Exists(inputFile))
				{
					File.Create(inputFile);
				}
				FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
				var rijndaelManaged = new RijndaelManaged();
				var cryptoStream = new CryptoStream(fsCrypt, rijndaelManaged.CreateDecryptor(key, key), CryptoStreamMode.Read);
				var fileStream = new FileStream(outputFile, FileMode.Create);

				try
				{
					int data;
					while ((data = cryptoStream.ReadByte()) != -1)
						fileStream.WriteByte((byte)data);
				}
				catch { throw; }
				finally
				{
					fsCrypt.Close();
					fileStream.Close();
					cryptoStream.Close();
				}
			}
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:30,代码来源:EncryptHelper.cs

示例5: Decrypt

        public static string Decrypt(this string encrypted)
        {
            if (string.IsNullOrEmpty(encrypted)) { return string.Empty; }

            RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
            ICryptoTransform decryptor = rc2CSP.CreateDecryptor(Convert.FromBase64String(Key), Convert.FromBase64String(IV));
            using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(encrypted)))
            {
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                {
                    List<Byte> bytes = new List<byte>();
                    int b;
                    do
                    {
                        b = csDecrypt.ReadByte();
                        if (b != -1)
                        {
                            bytes.Add(Convert.ToByte(b));
                        }

                    }
                    while (b != -1);

                    return Encoding.Unicode.GetString(bytes.ToArray());
                }
            }
        }
开发者ID:seniorOtaka,项目名称:ndoctor,代码行数:27,代码来源:PasswordExtension.cs

示例6: DecryptPassword

        public static string DecryptPassword(string encryptedText)
        {
            RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
            ICryptoTransform decryptor = rc2CSP.CreateDecryptor(rc2CSP.Key, rc2CSP.IV);
            using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(encryptedText)))
            {
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                {
                    List<Byte> bytes = new List<byte>();
                    int b;
                    do
                    {
                        b = csDecrypt.ReadByte();
                        if (b != -1)
                        {
                            bytes.Add(Convert.ToByte(b));
                        }

                    }
                    while (b != -1);

                    return Encoding.Unicode.GetString(bytes.ToArray());
                }
            }
        }
开发者ID:MarisV,项目名称:CourseWork-ASP.NET_MVC,代码行数:25,代码来源:CryptHelper.cs

示例7: ReadFile

        /// <summary>
        /// Ghi license ra file
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public static string ReadFile(string FilePath)
        {
            try
            {
                FileInfo fi = new FileInfo(FilePath);
                if (fi.Exists == false)
                    return string.Empty;

                FileStream fin = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
                TripleDES tdes = new TripleDESCryptoServiceProvider();
                CryptoStream cs = new CryptoStream(fin, tdes.CreateDecryptor(key, iv), CryptoStreamMode.Read);

                StringBuilder SB = new StringBuilder();
                int ch;
                for (int i = 0; i < fin.Length; i++)
                {
                    ch = cs.ReadByte();
                    if (ch == 0)
                        break;
                    SB.Append(Convert.ToChar(ch));
                }

                cs.Close();
                fin.Close();
                return SB.ToString();
            }
            catch(Exception ex)
            {
                return "";
            }
        }
开发者ID:romeobk,项目名称:HRMS_7Cua,代码行数:36,代码来源:FileReadWrite.cs

示例8: Decrypt

        public static void Decrypt(string srcPath, string destPath, int salt, string encryptionKey)
        {
            DeriveBytes rgb = new Rfc2898DeriveBytes(encryptionKey, Encoding.Unicode.GetBytes(salt.ToString()));

            using (SymmetricAlgorithm aes = new RijndaelManaged())
            {
                aes.BlockSize = 128;
                aes.KeySize = 256;
                aes.Key = rgb.GetBytes(aes.KeySize >> 3);
                aes.IV = rgb.GetBytes(aes.BlockSize >> 3);
                aes.Mode = CipherMode.CBC;
                Console.WriteLine("key : {0} , IV {1}\n", aes.Key.Length, aes.IV.Length);
                using (FileStream fsCrypt = new FileStream(srcPath, FileMode.Open))
                {
                    using (FileStream fsOut = new FileStream(destPath, FileMode.Create))
                    {
                        using (ICryptoTransform decryptor = aes.CreateDecryptor())
                        {
                            using (CryptoStream cs = new CryptoStream(fsCrypt, decryptor, CryptoStreamMode.Read))
                            {
                                int data;
                                while ((data = cs.ReadByte()) != -1)
                                {
                                    fsOut.WriteByte((byte)data);
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:lodio0,项目名称:Kryptografia,代码行数:31,代码来源:Szyfrowanie.cs

示例9: DecryptFile

        public static void DecryptFile(string inputFile, string outputFile, string skey)
        {
            try
            {
                using (Aes aes = new AesManaged() { KeySize = 256, BlockSize = 128 })
                {
                    var key = new Rfc2898DeriveBytes(skey, salt);

                    aes.Key = key.GetBytes(aes.KeySize / 8);
                    aes.IV = key.GetBytes(aes.BlockSize / 8);

                    using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
                    {
                        using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
                        {
                            using (ICryptoTransform decryptor = aes.CreateDecryptor())
                            {
                                using (CryptoStream cs = new CryptoStream(fsCrypt, decryptor, CryptoStreamMode.Read))
                                {
                                    int data;
                                    while ((data = cs.ReadByte()) != -1)
                                    {
                                        fsOut.WriteByte((byte)data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch { throw; }
        }
开发者ID:kaminskaarleta,项目名称:Zpi2WebApiWithLib,代码行数:32,代码来源:FileCryptography.cs

示例10: DecryptFile

        internal static void DecryptFile(string inputFile, string outputFile, string password)
        {

            {
                var UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                var fsCrypt = new FileStream(inputFile, FileMode.Open);

                var RMCrypto = new AesManaged();

                var cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateDecryptor(key, key),
                    CryptoStreamMode.Read);

                var fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte)data);

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();

            }
        }
开发者ID:RasyidUFA,项目名称:UFSJ,代码行数:27,代码来源:Shared.IO.cs

示例11: DecryptFile

        public static void DecryptFile(string inputFile, string outputFile, string password)
        {
            {
                //string password = @"myKey123"; // Your Key Here

                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                                                   RMCrypto.CreateDecryptor(key, key),
                                                   CryptoStreamMode.Read);

                FileStream fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte) data);

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();

            }
        }
开发者ID:hkuntal,项目名称:TeamWorkManagement,代码行数:28,代码来源:Program.cs

示例12: DecryptFile

        public static void DecryptFile(string sInputFilename,
           string sOutputFilename,
           string sKey)
        {
            DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

            DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

            FileStream fsread = new FileStream(sInputFilename,
               FileMode.Open,
               FileAccess.Read);
            ICryptoTransform desdecrypt = DES.CreateDecryptor();
            CryptoStream cryptostreamDecr = new CryptoStream(fsread,
               desdecrypt,
               CryptoStreamMode.Read);

            FileStream fswrite = new FileStream(sOutputFilename,
                FileMode.Create,
                FileAccess.Write);

            int b;
            while ((b = cryptostreamDecr.ReadByte()) >= 0)
            {
                fswrite.WriteByte((byte) b);
            }

            fswrite.Close();
            cryptostreamDecr.Close();
            fsread.Close();
        } 
开发者ID:skicean,项目名称:ZhongHuaSanGuoZhi,代码行数:31,代码来源:FileEncryptor.cs

示例13: Decrypt

        public static byte[] Decrypt(SymmetricAlgorithm algorithm,byte[] data)
        {
            using (MemoryStream memory = new MemoryStream(data))
            {
                using (CryptoStream decrypt = new CryptoStream(memory, algorithm.CreateDecryptor(algorithm.Key, algorithm.IV), CryptoStreamMode.Read))
                {
                    var result = new List<byte>();
                    var ibyte = decrypt.ReadByte();
                    while(ibyte > -1)
                    {
                        result.Add((byte)ibyte);
                        ibyte = decrypt.ReadByte();
                    }
                    return result.ToArray();
                }

            }
        }
开发者ID:node-net,项目名称:Node.Net,代码行数:18,代码来源:SymmetricAlgorithm.Extension.cs

示例14: ComputeSha1

        public static String ComputeSha1(string fileName)
        {
            using (var sha1Managed = new SHA1Managed())
            using (Stream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            using (Stream sha1Stream = new CryptoStream(fileStream, sha1Managed, CryptoStreamMode.Read))
            {
                while (sha1Stream.ReadByte() != -1);

                return Convert.ToBase64String(sha1Managed.Hash);
            }
        }
开发者ID:berkeleysquare,项目名称:ds3_net_sdk,代码行数:11,代码来源:Ds3TestUtils.cs

示例15: Byte2String

 public static string Byte2String(CryptoStream stream)
 {
     string x= "";
     int i = 0;
     do
     {
         i = stream.ReadByte();
         if (i != -1) x += ((char)i);
     } while (i != -1);
     return (x);
 }
开发者ID:Birajpjpt,项目名称:AES-Encryptor,代码行数:11,代码来源:Program.cs


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