コード例 #1
0
        public static string Encrypt(string value)
        {
            Verify.ArgumentNotNullOrEmpty(value, "value");

            // Declare the streams used
            // to encrypt to an in memory
            // array of bytes.
            MemoryStream   msEncrypt = null;
            CryptoStream   csEncrypt = null;
            C1StreamWriter swEncrypt = null;

            // Declare the RijndaelManaged object
            // used to encrypt the data.
            RijndaelManaged rima = null;

            try
            {
                // Create a RijndaelManaged object
                // with the specified key and IV.
                rima     = new RijndaelManaged();
                rima.Key = _encryptionKey;
                rima.IV  = RijndaelIV;

                // Create a decrytor to perform the stream transform.
                ICryptoTransform encryptor = rima.CreateEncryptor();

                // Create the streams used for encryption.
                msEncrypt = new MemoryStream();
                csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
                swEncrypt = new C1StreamWriter(csEncrypt);

                //Write all data to the stream.
                swEncrypt.Write(value);
            }
            finally
            {
                if (swEncrypt != null)
                {
                    swEncrypt.Close();
                }
                if (csEncrypt != null)
                {
                    csEncrypt.Close();
                }
                if (msEncrypt != null)
                {
                    msEncrypt.Close();
                }
                if (rima != null)
                {
                    rima.Clear();
                }
            }

            // Return the encrypted bytes from the memory stream.
            return(ByteToHexString(msEncrypt.ToArray()));
        }
コード例 #2
0
        /// <exclude/>
        public override IEnumerable <XElement> Install()
        {
            Verify.IsNotNull(_contentToAdd, "FileModifyPackageFragmentInstaller has not been validated");

            foreach (ContentToAdd content in _contentToAdd)
            {
                if (C1File.Exists(content.Path))
                {
                    using (C1StreamWriter sw = C1File.AppendText(content.Path))
                    {
                        sw.Write(content.Content);
                        sw.Close();
                    }
                }
                else
                {
                    C1File.WriteAllText(content.Path, content.Content);
                }
            }
            return(new[] { this.Configuration.FirstOrDefault() });
        }