示例#1
0
        /// <summary>
        /// Measure cipher performance in MB/s
        /// </summary>
        /// <param name="cipher">Cipher instance</param>
        /// <returns>Speed in MB/s</returns>
        public static string SpeedTest(ICipherAlgorithm cipher)
        {
            const int SAMPLE_SIZE_KB = 4;
            const int TEST_CYCLES    = 1024;

            byte[] plainText = new byte[SAMPLE_SIZE_KB * 1024];
            byte[] key       = new byte[cipher.KeyLength];
            byte[] iv        = new byte[cipher.BlockSize];

            Random rng = new Random();

            rng.NextBytes(plainText);
            rng.NextBytes(key);
            rng.NextBytes(iv);

            CipherEngine engine       = new CipherEngine(cipher);
            Stream       cipherStream = engine.EncryptStream(new MemoryStream(), key, iv);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int c = 0; c < TEST_CYCLES; c++)
            {
                using (MemoryStream plainTextStream = new MemoryStream(plainText)) {
                    plainTextStream.WriteTo(cipherStream);
                }
            }
            sw.Stop();

            return(String.Format("{0} = {1:0.00} KB/s", cipher.Name, (float)((1000.0 * SAMPLE_SIZE_KB * TEST_CYCLES) / (sw.ElapsedMilliseconds * 1.0))));
        }
示例#2
0
        /// <summary>
        /// Measure cipher performance in MB/s
        /// </summary>
        /// <param name="cipher">Cipher instance</param>
        /// <returns>Speed in MB/s</returns>
        public static string SpeedTest(ICipherAlgorithm cipher)
        {
            const int SAMPLE_SIZE_KB = 4;
            const int TEST_CYCLES = 1024;

            byte[] plainText = new byte[SAMPLE_SIZE_KB * 1024];
            byte[] key = new byte[cipher.KeyLength];
            byte[] iv = new byte[cipher.BlockSize];

            Random rng = new Random();
            rng.NextBytes(plainText);
            rng.NextBytes(key);
            rng.NextBytes(iv);

            CipherEngine engine = new CipherEngine(cipher);
            Stream cipherStream = engine.EncryptStream(new MemoryStream(), key, iv);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int c = 0; c < TEST_CYCLES; c++) {
                using (MemoryStream plainTextStream = new MemoryStream(plainText)) {
                    plainTextStream.WriteTo(cipherStream);
                }
            }
            sw.Stop();

            return String.Format("{0} = {1:0.00} KB/s", cipher.Name, (float)((1000.0 * SAMPLE_SIZE_KB * TEST_CYCLES) / (sw.ElapsedMilliseconds * 1.0)));
        }
示例#3
0
        public CFBTransform(byte[] pbKey, byte[] pbIV, bool bEncrypt, ICipherAlgorithm cipher)
        {
            _cipher = cipher;
            _cipher.SetKey(pbKey);

            _encrypt = bEncrypt;

            _state = new byte[_cipher.BlockSize];
            Array.Copy(pbIV, _state, _cipher.BlockSize);
        }
示例#4
0
        public CFBTransform(byte[] pbKey, byte[] pbIV, bool bEncrypt, ICipherAlgorithm cipher)
        {
            _cipher = cipher;
            _cipher.SetKey(pbKey);

            _encrypt = bEncrypt;

            _state = new byte[_cipher.BlockSize];
            Array.Copy(pbIV, _state, _cipher.BlockSize);
        }
示例#5
0
 public CipherEngine(ICipherAlgorithm cipher)
 {
     _cipher = cipher;
     _cipherUUID = new PwUuid(_cipher.UuidBytes);
 }
 public CipherEngine(ICipherAlgorithm cipher)
 {
     _cipher = cipher;
 }
示例#7
0
 public CipherEngine(ICipherAlgorithm cipher)
 {
     _cipher     = cipher;
     _cipherUUID = new PwUuid(_cipher.UuidBytes);
 }