예제 #1
0
        public void decrypt()
        {
            // now we use try catch, in the event something bad happens <3

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "RuSimpleCrypt";

                using (FileStream output = new FileStream(@filename.Replace(".aes", ""), FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    byte[] buffer = new byte[1024 * 4];

                    Stream input = new FileStream(@filename, FileMode.Open, FileAccess.Read);
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, input, SharpAESCrypt.OperationMode.Decrypt);
                    long fileLength       = input.Length;
                    long totalBytes       = 0;
                    int  currentBlockSize = 0;



                    while ((currentBlockSize = aesStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        totalBytes += currentBlockSize;
                        percentage  = (double)totalBytes * 100.0 / fileLength;
                        update_progressbar(percentage);
                        output.Write(buffer, 0, currentBlockSize);
                    }

                    input.Close();
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        public void decrypt()
        {
            // now we use try catch, in the event something bad happens <3

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "SimpleCrypt";

                using (FileStream output = new FileStream(@filename.Replace(".aes", ""), FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {

                    byte[] buffer = new byte[1024 * 4];

                    Stream input = new FileStream(@filename, FileMode.Open, FileAccess.Read);
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, input, SharpAESCrypt.OperationMode.Decrypt);
                    long fileLength = input.Length;
                    long totalBytes = 0;
                    int currentBlockSize = 0;

                    while ((currentBlockSize = aesStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        totalBytes += currentBlockSize;
                        percentage = (double)totalBytes * 100.0 / fileLength;
                        update_progressbar(percentage);
                        output.Write(buffer, 0, currentBlockSize);
                    }

                    input.Close();
                }

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        /// <inheritdoc cref="IAesCryptor"/>
        /// <summary>
        /// Encrypts the file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="password">The password.</param>
        public void EncryptFile(string fileName, string password)
        {
            var encryptedFile = GetEncryptedFileName(fileName);

            DeleteFileIfExists(encryptedFile);
            Crypt.Encrypt(password, fileName, encryptedFile);
            DeleteFileIfExists(fileName);
        }
예제 #4
0
        /// <summary>
        /// Decrypts the stream to the output stream
        /// </summary>
        /// <param name="input">The encrypted stream</param>
        /// <returns>The unencrypted stream</returns>
        public override Stream Decrypt(Stream input)
        {
            var cryptoStream = new SharpAESCrypt.SharpAESCrypt(m_key, input, SharpAESCrypt.OperationMode.Decrypt);

            if (m_usethreadlevel != 0)
            {
                cryptoStream.MaxCryptoThreads = m_usethreadlevel;
            }
            return(cryptoStream);
        }
예제 #5
0
        /// <inheritdoc cref="IFileCryptor"/>
        /// <summary>
        /// Encrypts the file.
        /// </summary>
        /// <param name="fileName">The file name.</param>
        /// <param name="outputFolder">The output folder.</param>
        /// <returns>An <see cref="UploadItem"/>.</returns>
        /// <seealso cref="IFileCryptor"/>
        public UploadItem EncryptFile(string fileName, string outputFolder)
        {
            CheckFileName(fileName);
            var password    = this.randomizer.GetRandomPassword();
            var newFileName = this.GetNewFileName(fileName, outputFolder);

            AESCrypt.Encrypt(password, fileName, newFileName);
            var documentationFile = GetDocumentationFileName(fileName, outputFolder);

            return(GetNewUploadItem(fileName, documentationFile, newFileName, password));
        }
예제 #6
0
        /// <summary>
        /// Decrypts the data.
        /// </summary>
        /// <param name="encryptedData">The encrypted data.</param>
        /// <param name="password">The password.</param>
        /// <returns>A <see cref="string/> containing the decrypted data.</returns>
        private static string DecryptData(byte[] encryptedData, string password)
        {
            string normalText;

            using (var encryptedStream = new MemoryStream(encryptedData))
            {
                using (var normalStream = new MemoryStream())
                {
                    Crypt.Decrypt(password, encryptedStream, normalStream);
                    var normalBytes = normalStream.ToArray();
                    normalText = Encoding.UTF8.GetString(normalBytes);
                }
            }
            return(normalText);
        }
예제 #7
0
        public void encrypt()
        {
            // we do this to handle any errors

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "SimpleCrypt";
                using (FileStream output = new FileStream(@filename + ".aes", FileMode.Create, FileAccess.ReadWrite))
                {
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, output, SharpAESCrypt.OperationMode.Encrypt);
                    // now we set the extension information

                    byte[] buffer = new byte[1024 * 4];

                    using (FileStream input = new FileStream(@filename, FileMode.Open, FileAccess.Read))
                    {

                        long fileLength = input.Length;
                        long totalBytes = 0;
                        int currentBlockSize = 0;

                        while ((currentBlockSize = input.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            totalBytes += currentBlockSize;
                            percentage = (double)totalBytes * 100.0 / fileLength;
                            update_progressbar(percentage);

                            aesStream.Write(buffer, 0, currentBlockSize);
                        }

                        aesStream.FlushFinalBlock();

                    }

                }

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #8
0
        public void encrypt()
        {
            // we do this to handle any errors

            try {
                SharpAESCrypt.SharpAESCrypt.Extension_CreatedByIdentifier = "RuSimpleCrypt";
                using (FileStream output = new FileStream(@filename + ".aes", FileMode.Create, FileAccess.ReadWrite))
                {
                    SharpAESCrypt.SharpAESCrypt aesStream = new SharpAESCrypt.SharpAESCrypt(password, output, SharpAESCrypt.OperationMode.Encrypt);
                    // now we set the extension information

                    byte[] buffer = new byte[1024 * 4];

                    using (FileStream input = new FileStream(@filename, FileMode.Open, FileAccess.Read))
                    {
                        long fileLength       = input.Length;
                        long totalBytes       = 0;
                        int  currentBlockSize = 0;

                        while ((currentBlockSize = input.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            totalBytes += currentBlockSize;
                            percentage  = (double)totalBytes * 100.0 / fileLength;
                            update_progressbar(percentage);

                            aesStream.Write(buffer, 0, currentBlockSize);
                        }

                        aesStream.FlushFinalBlock();
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #9
0
 /// <summary>
 /// Decrypts the stream to the output stream
 /// </summary>
 /// <param name="input">The encrypted stream</param>
 /// <returns>The unencrypted stream</returns>
 public override Stream Decrypt(Stream input)
 {
     var cryptoStream = new SharpAESCrypt.SharpAESCrypt(m_key, input, SharpAESCrypt.OperationMode.Decrypt);
     if (m_usethreadlevel != 0) cryptoStream.MaxCryptoThreads = m_usethreadlevel;
     return cryptoStream;
 }