示例#1
0
        public async Task EncryptFileTest()
        {
            // Arrange
            var aes = new SimpleAes(key);

            // Act
            await aes.EncryptAsync(testFile, cryptFile);

            // Assert
            Assert.IsTrue(File.Exists(cryptFile));
        }
示例#2
0
        public async Task EncryptTest()
        {
            // Arrange
            var aes = new SimpleAes(key);

            // Act
            string encrypted = await aes.EncryptAsync(sample);

            // Assert
            Assert.AreEqual(result, encrypted);
        }
示例#3
0
        public async Task DecryptEncryptFileTest()
        {
            // Arrange
            var aes = new SimpleAes(key);

            // Act
            await aes.DecryptAsync(testCryptFile, outFile);

            await aes.EncryptAsync(outFile, cryptFile);

            // Assert
            Assert.AreEqual(File.ReadAllText(testCryptFile), File.ReadAllText(cryptFile));
        }
示例#4
0
        public async Task EncryptStreamTest()
        {
            // Arrange
            var aes = new SimpleAes(key);

            using var ms = new MemoryStream(Encoding.UTF8.GetBytes(sample));

            // Act
            byte[] encrypted = await aes.EncryptAsync(ms);

            string encStr = Convert.ToBase64String(encrypted);

            // Assert
            Assert.AreEqual(result, encStr);
        }
示例#5
0
        public async Task DecryptEncryptStreamTest()
        {
            // Arrange
            var aes = new SimpleAes(key);

            using var inStream = new MemoryStream(Convert.FromBase64String(result));

            // Act
            byte[] decrypted = await aes.DecryptAsync(inStream);

            using var outStream = new MemoryStream(decrypted);
            byte[] encrypted = await aes.EncryptAsync(outStream);

            string encStr = Convert.ToBase64String(encrypted);

            // Assert
            Assert.AreEqual(result, encStr);
        }
示例#6
0
        public async Task EncryptDecryptStreamTest()
        {
            // Arrange
            var aes = new SimpleAes(key);

            using var inStream = new MemoryStream(Encoding.UTF8.GetBytes(sample));

            // Act
            byte[] encrypted = await aes.EncryptAsync(inStream);

            using var outStream = new MemoryStream(encrypted);
            byte[] decrypted = await aes.DecryptAsync(outStream);

            string decStr = Encoding.UTF8.GetString(decrypted);

            // Assert
            Assert.AreEqual(sample, decStr);
        }