public void Encrypt(string expected, string input)
        {
            // Arrange
            using (var transform = m_algorithm.CreateEncryptor())
            {
                // Act
                var result = Convert.ToBase64String(CryptoTransformHelper.Encrypt(transform,
                                                                                  Encoding.UTF8.GetBytes(input)));

                // Assert
                Assert.NotNull(result);
                Assert.Equal(expected, result);
            }
        }
Exemple #2
0
        public void EncryptorContext(string expected, string input)
        {
            // Arrange
            string result = null;

            // Act
            m_context.EncryptorContext(transform =>
            {
                result = Convert.ToBase64String(CryptoTransformHelper.Encrypt(transform,
                                                                              Encoding.UTF8.GetBytes(input)));
            });

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expected, result);
        }
        public void Encrypt_Decrypt()
        {
            // Arrange
            var input = RandomHelper.NextSentence(g_random, RandomHelper.NextInt(g_random, 20, 40));

            using (var encryptor = m_algorithm.CreateEncryptor())
            {
                using (var decryptor = m_algorithm.CreateDecryptor())
                {
                    // Act
                    var result = Encoding.UTF8.GetString(CryptoTransformHelper.Decrypt(decryptor,
                                                                                       CryptoTransformHelper.Encrypt(encryptor, Encoding.UTF8.GetBytes(input))));

                    // Assert
                    Assert.NotNull(result);
                    Assert.Equal(input, result);
                }
            }
        }
 public override ArraySegment <byte> Encrypt(ArraySegment <byte> data)
 {
     return(CryptoTransformHelper.Encrypt(m_encryptor, data));
 }