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


C# CryptoStream.WriteByte方法代码示例

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


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

示例1: DecryptFile

        public static void DecryptFile(string strKey, string pathCypheredTextFile, string pathPlainTextFile)
        {
            // Place la clé de déchiffrement dans un tableau d'octets
            byte[] key = GenerateAlgotihmInputs(strKey);

            // Place le vecteur d'initialisation dans un tableau d'octets
            byte[] iv = GenerateAlgotihmInputs(strKey);

            // Filestream of the new file that will be decrypted.
            Directory.CreateDirectory(Directory.GetParent(pathPlainTextFile).FullName);
            FileStream fsCrypt = new FileStream(pathPlainTextFile, FileMode.Create);

            RijndaelManaged rijndael = new RijndaelManaged();
            rijndael.Mode = CipherMode.CBC;
            rijndael.Key = key;
            rijndael.IV = iv;

            ICryptoTransform aesDecryptor = rijndael.CreateDecryptor();

            CryptoStream cs = new CryptoStream(fsCrypt, aesDecryptor, CryptoStreamMode.Write);

            // FileStream of the file that is currently encrypted.
            FileStream fsIn = new FileStream(pathCypheredTextFile, FileMode.OpenOrCreate);

            int data;

            while ((data = fsIn.ReadByte()) != -1)
                cs.WriteByte((byte)data);
            cs.Close();
            fsIn.Close();
            fsCrypt.Close();
        }
开发者ID:BenoitCharret,项目名称:visualStudio,代码行数:32,代码来源:EncryptionHelper.cs

示例2: EncryptFile

 public void EncryptFile(string inputFile, string outputFile, string securityKey)
 {
     try
     {
         using (RijndaelManaged aes = new RijndaelManaged())
         {
             byte[] key = ASCIIEncoding.UTF8.GetBytes(securityKey);
             byte[] IV = ASCIIEncoding.UTF8.GetBytes("1234567890qwerty");
             //aes.Padding = PaddingMode.None;
             using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
             {
                 Console.WriteLine("File created.");
                 using (ICryptoTransform encryptor = aes.CreateEncryptor(key, IV))
                 {
                     Console.WriteLine("Encrypt mode initiated.");
                     using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
                     {
                         Console.WriteLine("Encrypt stream initiated.");
                         using (FileStream fsIn = new FileStream(inputFile, FileMode.Open, FileAccess.Read))
                         {
                             int data;
                             while ((data = fsIn.ReadByte()) != -1)
                             {
                                 cs.WriteByte((byte)data);
                             }
                             Console.WriteLine("File encrypted.");
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("This exception was caught: " + ex.ToString());
     }
 }
开发者ID:TimurKiyivinski,项目名称:TenantAdministrationSystem,代码行数:37,代码来源:Shared.cs

示例3: encryption

        public void encryption()
        {
            byte[] file = new byte[FileUpload1.PostedFile.ContentLength];
            FileUpload1.PostedFile.InputStream.Read(file, 0, FileUpload1.PostedFile.ContentLength);
            string fileName = txtfilename.Text;
            byte[] Key = Encoding.UTF8.GetBytes(LTRPRIKEY.Text);
            ASCIIEncoding.ASCII.GetString(Key);
            try
            {
                string outputFile = Path.Combine(Server.MapPath("~/uploadfiles/advance"), fileName);

                FileStream fs = new FileStream(outputFile, FileMode.Create);
                RijndaelManaged rmCryp = new RijndaelManaged();
                CryptoStream cs = new CryptoStream(fs, rmCryp.CreateEncryptor(Key, Key), CryptoStreamMode.Write);
                foreach (var data in file)
                {
                    cs.WriteByte((byte)data);
                }
                cs.Close();
                fs.Close();
                insert();


            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "popup",
                   "alert(" + ex + ");", true);
            }
        }
开发者ID:neerajbattish,项目名称:files1,代码行数:30,代码来源:uploadadvnce.aspx.cs

示例4: EncryptFile

        public static void EncryptFile(string inputFile, string outputFile, string skey)
        {
            try
            {
                using (Aes aes = new AesManaged())
                {
                    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(outputFile, FileMode.Create))
                    {
                        using (ICryptoTransform encryptor = aes.CreateEncryptor())
                        {
                            using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
                            {
                                using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
                                {
                                    int data;
                                    while ((data = fsIn.ReadByte()) != -1)
                                    {
                                        cs.WriteByte((byte)data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch { throw; }
        }
开发者ID:kaminskaarleta,项目名称:Zpi2WebApiWithLib,代码行数:32,代码来源:FileCryptography.cs

示例5: Encrypt

        public static void Encrypt(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;
                string key = "";
                string iv = "";
                using (FileStream fsCrypt = new FileStream(destPath, FileMode.Create))
                {
                    using (ICryptoTransform encryptor = aes.CreateEncryptor())
                    {
                        using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
                        {
                            using (FileStream fsIn = new FileStream(srcPath, FileMode.Open))
                            {
                                int data;
                                while ((data = fsIn.ReadByte()) != -1)
                                {
                                    cs.WriteByte((byte)data);
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:lodio0,项目名称:Kryptografia,代码行数:32,代码来源:Szyfrowanie.cs

示例6: EncryptFile

        public static void EncryptFile(string inputFile, string outputFile, string password)
        {
            try
            {
                //string password = @"myKey123"; // Your Key Here
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                string cryptFile = outputFile;
                FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                                                   RMCrypto.CreateEncryptor(key, key),
                                                   CryptoStreamMode.Write);

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

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

                fsIn.Close();
                cs.Close();
                fsCrypt.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Encryption failed! {0}", ex);
            }
        }
开发者ID:hkuntal,项目名称:TeamWorkManagement,代码行数:32,代码来源:Program.cs

示例7: EncryptFile

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

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

                string cryptFile = outputFile;
                var fsCrypt = new FileStream(cryptFile, FileMode.Create);

                var AesMngd = new AesManaged();

                var cs = new CryptoStream(fsCrypt,
                    AesMngd.CreateEncryptor(key, key),
                    CryptoStreamMode.Write);

                using (var fsIn = new FileStream(inputFile, FileMode.Open)) {
                    int data;
                    while ((data = fsIn.ReadByte()) != -1)
                        cs.WriteByte((byte)data);
                }
                cs.Close();
                fsCrypt.Close();
            } catch {
                Shared.MSGBOX(Shared.GetRes("#D.02#","Error"),"Encryption failed!",System.Windows.Application.Current.MainWindow);
            }
        }
开发者ID:RasyidUFA,项目名称:UFSJ,代码行数:27,代码来源:Shared.IO.cs

示例8: DecryptStringWith3DES

        public static string DecryptStringWith3DES(string data, string key, string iv)
        {
            UnicodeEncoding unicode = new UnicodeEncoding();
            Byte[] Bytes = Convert.FromBase64String(data);

            MemoryStream mem = new MemoryStream(100);
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

            Byte[] KeyBytes = unicode.GetBytes(key);
            Byte[] tmpBytes = new Byte[16];
            Array.Copy(KeyBytes, tmpBytes, KeyBytes.Length < 16 ? KeyBytes.Length : 16);
            KeyBytes = tmpBytes;

            if(tdes.ValidKeySize(KeyBytes.Length*8))
                System.Diagnostics.Debug.WriteLine("Key size valid");
            if(TripleDESCryptoServiceProvider.IsWeakKey(KeyBytes))
                System.Diagnostics.Debug.WriteLine("Key weak");
            CryptoStream CrStream = new CryptoStream(mem, tdes.CreateDecryptor(KeyBytes, unicode.GetBytes(iv)), CryptoStreamMode.Write);

            for(int i = 0; i < Bytes.Length; i++)
                CrStream.WriteByte(Bytes[i]);

            CrStream.FlushFinalBlock();

            string result = unicode.GetString(mem.GetBuffer(), 0, (int)mem.Length);
            CrStream.Dispose();
            return result;
        }
开发者ID:cyotek,项目名称:translateclient,代码行数:28,代码来源:CryptoTools.cs

示例9: Encrypt

        public static string Encrypt(this ICryptoTransform crypto, SecureString toEncrypt)
        {
            using (crypto)
            using (MemoryStream memStream = new MemoryStream())
            using (CryptoStream crypStream = new CryptoStream(memStream, crypto, CryptoStreamMode.Write))
            {
                IntPtr bstr = Marshal.SecureStringToBSTR(toEncrypt);

                try
                {
                    byte b;
                    for (int index = 0; index < toEncrypt.Length * 2; index = index + 2)
                    {
                        b = Marshal.ReadByte(bstr, index);
                        crypStream.WriteByte(b);
                    }
                    b = 0;

                    crypStream.FlushFinalBlock();
                }
                finally
                {
                    Marshal.ZeroFreeBSTR(bstr);
                }

                return Convert.ToBase64String(memStream.ToArray());
            }
        }
开发者ID:GetPlay,项目名称:Mangos-TEx,代码行数:28,代码来源:CryptoHelper.cs

示例10: EncryptFile

        private static void EncryptFile(string inputFile, string outputFile, string password)
        {
            try
            {
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                string cryptFile = outputFile;
                FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateEncryptor(key, key),
                    CryptoStreamMode.Write);

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

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

                fsIn.Close();
                cs.Close();
                fsCrypt.Close();
            }
            catch (Exception e)
            {
                throw new Exception("Encryption failed! Error", e);
            }
        }
开发者ID:SujaanKanwar,项目名称:Service_MadMoney,代码行数:31,代码来源:Program.cs

示例11: EncryptFile

 public bool EncryptFile(byte[] aPublicKey, byte[] aIV, string aFileName)
 {
     try
     {
         int num;
         string path = aFileName;
         FileStream stream = new FileStream(aFileName + ".enc", FileMode.Create);
         RijndaelManaged managed = new RijndaelManaged();
         CryptoStream stream2 = new CryptoStream(stream, managed.CreateEncryptor(aPublicKey, aIV), CryptoStreamMode.Write);
         FileStream stream3 = new FileStream(path, FileMode.Open);
         int bytecount = 0;
         while ((num = stream3.ReadByte()) != -1)
         {
             bytecount += num;
             stream2.WriteByte((byte) num);
             if (this.OnEncryptAmount != null)
             {
                 this.OnEncryptAmount(bytecount);
             }
         }
         stream3.Close();
         stream2.Close();
         stream.Close();
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:micheljung,项目名称:gpgnetfix,代码行数:30,代码来源:Crypto.cs

示例12: EncryptToFile

        ///<summary>
        /// Encrypts a file using Rijndael algorithm.
        ///</summary>
        ///<param name="inputFile"></param>
        ///<param name="outputFile"></param>
        public static void EncryptToFile(this string data, string outputFile, string password)
        {
            try
            {
                byte[] key = Encoding.UTF8.GetBytes(password);

                string cryptFile = outputFile;
                using (FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create))
                {
                    using (RijndaelManaged RMCrypto = new RijndaelManaged())
                    {
                        CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateEncryptor(key, key), CryptoStreamMode.Write);
                        using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data)))
                        {
                            int datavar;
                            while ((datavar = ms.ReadByte()) != -1)
                                cs.WriteByte((byte)datavar);

                        }
                    }
                }
            }
            catch
            {
            }
        }
开发者ID:OleksandrKulchytskyi,项目名称:Sharedeployed,代码行数:31,代码来源:FileHelper.cs

示例13: EncryptFile

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

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

               using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
               {
                   using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateEncryptor(key, key), CryptoStreamMode.Write))
                   {
                       using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
                       {
                           int data;

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

                           aes.Clear();
                       }

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

示例14: WriteFile

        public static void WriteFile(string FilePath, string Data)
        {
            FileStream fout = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write);
            TripleDES tdes = new TripleDESCryptoServiceProvider();
            CryptoStream cs = new CryptoStream(fout, tdes.CreateEncryptor(key, iv), CryptoStreamMode.Write);

            byte[] d = Encoding.ASCII.GetBytes(Data);
            cs.Write(d, 0, d.Length);
            cs.WriteByte(0);

            cs.Close();
            fout.Close();
        }
开发者ID:ninianh,项目名称:PhongKham,代码行数:13,代码来源:FileReadWrite.cs

示例15: Encrypt

        private static void Encrypt(string inputFile, string outputFile)
        {
            byte[] bytes = new UnicodeEncoding().GetBytes(KEY);
            RijndaelManaged rijndaelManaged = new RijndaelManaged();

            using(FileStream outputStream = new FileStream(outputFile, FileMode.Create))
            using(CryptoStream cryptoStream = new CryptoStream((Stream)outputStream, rijndaelManaged.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write))
            using(FileStream inputStream = new FileStream(inputFile, FileMode.Open))
            {
                int num;
                while ((num = inputStream.ReadByte()) != -1)
                {
                    cryptoStream.WriteByte((byte)num);
                }
            }
        }
开发者ID:roddy,项目名称:TEdit,代码行数:16,代码来源:PlrWriter.cs


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