Ejemplo n.º 1
0
        public async Task DecryptEncryptStreamTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

            using var inStream1 = new MemoryStream(Convert.FromBase64String(result1));
            using var inStream2 = new MemoryStream(Convert.FromBase64String(result2));

            // Act
            byte[] decrypted1 = await tDes1.DecryptAsync(inStream1);

            byte[] decrypted2 = await tDes2.DecryptAsync(inStream2);

            string decStr1 = Convert.ToBase64String(decrypted1);
            string decStr2 = Convert.ToBase64String(decrypted2);

            using var outStream1 = new MemoryStream(decrypted1);
            using var outStream2 = new MemoryStream(decrypted2);
            byte[] encrypted1 = await tDes1.EncryptAsync(outStream1);

            byte[] encrypted2 = await tDes2.EncryptAsync(outStream2);

            string encStr1 = Convert.ToBase64String(encrypted1);
            string encStr2 = Convert.ToBase64String(encrypted2);

            // Assert
            Assert.AreEqual(result1, encStr1);
            Assert.AreEqual(result2, encStr2);
            Assert.AreEqual(decStr1, decStr2);
            Assert.AreNotEqual(encStr1, encStr2);
        }
Ejemplo n.º 2
0
        public async Task EncryptDecryptStreamTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

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

            // Act
            byte[] encrypted1 = await tDes1.EncryptAsync(inStream1);

            byte[] encrypted2 = await tDes2.EncryptAsync(inStream2);

            using var outStream1 = new MemoryStream(encrypted1);
            using var outStream2 = new MemoryStream(encrypted2);
            byte[] decrypted1 = await tDes1.DecryptAsync(outStream1);

            byte[] decrypted2 = await tDes2.DecryptAsync(outStream2);

            string decStr1 = Encoding.UTF8.GetString(decrypted1);
            string decStr2 = Encoding.UTF8.GetString(decrypted2);

            // Assert
            Assert.AreEqual(sample, decStr1);
            Assert.AreEqual(sample, decStr2);
            Assert.AreNotEqual(encrypted1, encrypted2);
            Assert.AreEqual(decStr1, decStr2);
        }
Ejemplo n.º 3
0
        public async Task DecryptTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

            // Act
            string decrypted1 = await tDes1.DecryptAsync(result1);

            string decrypted2 = await tDes2.DecryptAsync(result2);

            // Assert
            Assert.AreEqual(sample, decrypted1);
            Assert.AreEqual(sample, decrypted2);
        }
Ejemplo n.º 4
0
        public async Task DecryptFileTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

            // Act
            await tDes1.DecryptAsync(testCryptFile1, outFile1);

            await tDes2.DecryptAsync(testCryptFile2, outFile2);

            // Assert
            Assert.IsTrue(File.Exists(outFile1));
            Assert.IsTrue(File.Exists(outFile2));
            Assert.AreEqual(File.ReadAllText(outFile1), File.ReadAllText(outFile2));
        }
Ejemplo n.º 5
0
        public async Task EncryptFileTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

            // Act
            await tDes1.EncryptAsync(testFile, cryptFile1);

            await tDes2.EncryptAsync(testFile, cryptFile2);

            // Assert
            Assert.IsTrue(File.Exists(cryptFile1));
            Assert.IsTrue(File.Exists(cryptFile2));
            Assert.AreNotEqual(File.ReadAllBytes(cryptFile1), File.ReadAllBytes(cryptFile2));
        }
Ejemplo n.º 6
0
        public async Task EncryptTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

            // Act
            string encrypted1 = await tDes1.EncryptAsync(sample);

            string encrypted2 = await tDes2.EncryptAsync(sample);

            //Debug.WriteLine(encrypted);

            // Assert
            Assert.AreEqual(result1, encrypted1);
            Assert.AreEqual(result2, encrypted2);
            Assert.AreNotEqual(encrypted1, encrypted2);
        }
Ejemplo n.º 7
0
        public async Task EncryptStreamTest()
        {
            // Arrange
            var tDes1 = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2 = new SimpleTripleDes(key, TripleDesKeySize.b192);

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

            // Act
            byte[] encrypted1 = await tDes1.EncryptAsync(ms1);

            byte[] encrypted2 = await tDes2.EncryptAsync(ms2);

            string encStr1 = Convert.ToBase64String(encrypted1);
            string encStr2 = Convert.ToBase64String(encrypted2);

            // Assert
            Assert.AreEqual(result1, encStr1);
            Assert.AreEqual(result2, encStr2);
            Assert.AreNotEqual(encStr1, encStr2);
        }
Ejemplo n.º 8
0
        public async Task DecryptStreamTest()
        {
            // Arrange
            var tDes1  = new SimpleTripleDes(key, TripleDesKeySize.b128);
            var tDes2  = new SimpleTripleDes(key, TripleDesKeySize.b192);
            var bytes1 = Convert.FromBase64String(result1);
            var bytes2 = Convert.FromBase64String(result2);

            using var ms1 = new MemoryStream(bytes1);
            using var ms2 = new MemoryStream(bytes2);

            // Act
            byte[] decrypted1 = await tDes1.DecryptAsync(ms1);

            byte[] decrypted2 = await tDes2.DecryptAsync(ms2);

            var decStr1 = Encoding.UTF8.GetString(decrypted1);
            var decStr2 = Encoding.UTF8.GetString(decrypted2);

            // Assert
            Assert.AreEqual(sample, decStr1);
            Assert.AreEqual(sample, decStr2);
            Assert.AreEqual(decStr1, decStr2);
        }