Esempio n. 1
0
        public void Encrypt()
        {
            var data = "P@ssw0rd";

            var keys      = HybridEncryption.GenerateKeys();
            var encrypted = HybridEncryption.Encrypt(data, keys.PublicKey);
            var decrypted = HybridEncryption.Decrypt(encrypted, keys.KeysPair);

            Console.WriteLine(encrypted);
            Assert.AreEqual(data, decrypted);
        }
Esempio n. 2
0
        static void Encrypt_Stream(int dataSize)
        {
            var data            = CryptoHelper.GenerateBytes(dataSize);
            var keys            = HybridEncryption.GenerateKeys();
            var encryptedStream = new MemoryStream();
            var decryptedStream = new MemoryStream();

            HybridEncryption.Encrypt(new MemoryStream(data), encryptedStream, keys.PublicKey);
            var encrypted = encryptedStream.ToArray();

            HybridEncryption.Decrypt(new MemoryStream(encrypted), decryptedStream, keys.KeysPair);
            var decrypted = decryptedStream.ToArray();

            if (dataSize <= 1024)
            {
                Console.WriteLine(Convert.ToBase64String(encrypted));
            }
            CollectionAssert.AreEqual(data, decrypted);
        }