Ejemplo n.º 1
0
 /// <summary>
 /// Replaces the all files content with some new content
 /// </summary>
 /// <param name="file"></param>
 /// <param name="newContent"></param>
 public static void SetNewContent(this IFile file, string newContent)
 {
     using (C1StreamWriter sw = new C1StreamWriter(GetNewWriteStream(file)))
     {
         sw.Write(newContent);
     }
 }
Ejemplo n.º 2
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());
        }