Exemple #1
0
		/// <summary>
		/// For Unit testing: Decrypt a stream using the supplied password with changing (small) buffer sizes
		/// </summary>
		/// <param name="password">The password to decrypt with</param>
		/// <param name="input">The input stream</param>
		/// <param name="output">The output stream</param>
		private static void UnitStreamDecrypt(string password, Stream input, Stream output, int bufferSizeSelect, int useThreads)
		{
			var r = new Random();

			var partBufs = Math.Min(bufferSizeSelect, 1024);

			var buffers = new byte[partBufs][];
			for (int bs = 1; bs < partBufs; bs++)
				buffers[bs] = new byte[bs];

			buffers[0] = new byte[bufferSizeSelect];

			int a;
            using (input = new NonFulfillingReaderStream(input))
            {
                var c = new SharpAESCrypt(password, input, OperationMode.Decrypt, true);
                c.MaxCryptoThreads = useThreads;
                do
                {
                    var bufLen = r.Next(bufferSizeSelect) + 1;
                    var useBuf = bufLen < partBufs ? buffers[bufLen] : buffers[0];
                    a = c.Read(useBuf, 0, bufLen);
                    output.Write(useBuf, 0, a);
                } while (a != 0);
            }
		}
Exemple #2
0
        /// <summary>
        /// For Unit testing: Decrypt a stream using the supplied password with changing (small) buffer sizes
        /// </summary>
        /// <param name="password">The password to decrypt with</param>
        /// <param name="input">The input stream</param>
        /// <param name="output">The output stream</param>
        private static void UnitStreamDecrypt(string password, Stream input, Stream output, int bufferSizeSelect, int useThreads)
        {
            var r = new Random();

            var partBufs = Math.Min(bufferSizeSelect, 1024);

            var buffers = new byte[partBufs][];
            for (int bs = 1; bs < partBufs; bs++)
                buffers[bs] = new byte[bs];

            buffers[0] = new byte[bufferSizeSelect];

            int a;
            using (input = new NonFulfillingReaderStream(input))
            {
                var c = new SharpAESCrypt(password, input, OperationMode.Decrypt, true);
                c.MaxCryptoThreads = useThreads;
                do
                {
                    var bufLen = r.Next(bufferSizeSelect) + 1;
                    var useBuf = bufLen < partBufs ? buffers[bufLen] : buffers[0];
                    a = c.Read(useBuf, 0, bufLen);
                    output.Write(useBuf, 0, a);
                } while (a != 0);
            }
        }