Ejemplo n.º 1
0
        /// <summary>
        /// Reads the contents of the file.
        /// </summary>
        /// <param name="content">The content of the file downloaded</param>
        /// <returns>Decrypted content of the file</returns>
        protected override String ReadContent(Byte[] content)
        {
            CIRegistry registry  = new CIRegistry();
            String     secureKey = registry.ReadSecureKey();

            RijndaelManaged    crypto       = new RijndaelManaged();
            Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(registry.ReadSecureKey(), new Byte[] { 90, 32, 230, 20, 59, 78, 112, 183 });

            Byte[] key = derivedBytes.GetBytes(crypto.KeySize / 8);
            Byte[] iv  = derivedBytes.GetBytes(crypto.BlockSize / 8);

            using (MemoryStream ms = new MemoryStream(content))
                using (CryptoStream cs = new CryptoStream(ms, crypto.CreateDecryptor(key, iv), CryptoStreamMode.Read))
                    using (MemoryStream msOut = new MemoryStream())
                    {
                        Int32 buffer;
                        while ((buffer = cs.ReadByte()) != -1)
                        {
                            msOut.WriteByte((Byte)buffer);
                        }

                        msOut.Flush();
                        return(Encoding.Default.GetString(msOut.ToArray()));
                    }
        }
        /// <summary>
        /// Reads the contents of the file.
        /// </summary>
        /// <param name="content">The content of the file downloaded</param>
        /// <returns>Decrypted content of the file</returns>
        protected override String ReadContent(Byte[] content)
        {
            CIRegistry registry = new CIRegistry();
            String secureKey = registry.ReadSecureKey();

            RijndaelManaged crypto = new RijndaelManaged();
            Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(registry.ReadSecureKey(), new Byte[] { 90, 32, 230, 20, 59, 78, 112, 183 });
            Byte[] key = derivedBytes.GetBytes(crypto.KeySize / 8);
            Byte[] iv = derivedBytes.GetBytes(crypto.BlockSize / 8);

            using(MemoryStream ms = new MemoryStream(content))
            using(CryptoStream cs = new CryptoStream(ms, crypto.CreateDecryptor(key, iv), CryptoStreamMode.Read))
            using (MemoryStream msOut = new MemoryStream())
            {
                Int32 buffer;
                while ((buffer = cs.ReadByte()) != -1)
                    msOut.WriteByte((Byte)buffer);

                msOut.Flush();
                return Encoding.Default.GetString(msOut.ToArray());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Encrypts the file.
        /// </summary>
        /// <param name="inputFile">The input file.</param>
        /// <param name="outputFile">The output file.</param>
        private static void EncryptFile(String inputFile, String outputFile)
        {
            CIRegistry registry = new CIRegistry();
          
            RijndaelManaged crypto = new RijndaelManaged();
            Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(registry.ReadSecureKey(), new Byte[] { 90, 32, 230, 20, 59, 78, 112, 183 });
            Byte[] key = derivedBytes.GetBytes(crypto.KeySize / 8);
            Byte[] iv = derivedBytes.GetBytes(crypto.BlockSize / 8);

            Byte[] buffer = null;
            using (FileStream inFile = new FileStream(inputFile, FileMode.Open))
            {
                buffer = new Byte[inFile.Length];
                inFile.Read(buffer, 0, buffer.Length);
            }

            using(FileStream outFile = new FileStream(outputFile, FileMode.Create))
            using(CryptoStream cs = new CryptoStream(outFile, crypto.CreateEncryptor(key, iv), CryptoStreamMode.Write))
            {
                cs.Write(buffer, 0, buffer.Length);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Encrypts the file.
        /// </summary>
        /// <param name="inputFile">The input file.</param>
        /// <param name="outputFile">The output file.</param>
        private static void EncryptFile(String inputFile, String outputFile)
        {
            CIRegistry registry = new CIRegistry();

            RijndaelManaged    crypto       = new RijndaelManaged();
            Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(registry.ReadSecureKey(), new Byte[] { 90, 32, 230, 20, 59, 78, 112, 183 });

            Byte[] key = derivedBytes.GetBytes(crypto.KeySize / 8);
            Byte[] iv  = derivedBytes.GetBytes(crypto.BlockSize / 8);

            Byte[] buffer = null;
            using (FileStream inFile = new FileStream(inputFile, FileMode.Open))
            {
                buffer = new Byte[inFile.Length];
                inFile.Read(buffer, 0, buffer.Length);
            }

            using (FileStream outFile = new FileStream(outputFile, FileMode.Create))
                using (CryptoStream cs = new CryptoStream(outFile, crypto.CreateEncryptor(key, iv), CryptoStreamMode.Write))
                {
                    cs.Write(buffer, 0, buffer.Length);
                }
        }