public void EncryptAndDecryptStreamTest()
        {
            // Make a provider
            IBlobCryptoProvider asymmetricProvider = new AsymmetricBlobCryptoProvider();

            // In all cases we are READING from streams 
            // (read from original, read from encrypted, read from decrypted).
            var encryptedStream = asymmetricProvider.EncryptedStream(streamSample);
            var decryptedStream = asymmetricProvider.DecryptedStream(encryptedStream);

            byte[] result = new byte[sampleStreamSize];
            decryptedStream.Read(result, 0, result.Length);

            Assert.IsTrue(
                result.SequenceEqual(streamSample.ToArray()),
                "Decrypted data does not match original data");
        }
        public void DecryptFailsWithX509IfPrivateKeyNotLoadedTest()
        {
            // Load Certificate
            X509Certificate2 cert = new X509Certificate2("4096.pfx", string.Empty, X509KeyStorageFlags.Exportable);

            // Make a provider
            IBlobCryptoProvider asymmetricProvider = new AsymmetricBlobCryptoProvider(cert, false);

            // In all cases we are READING from streams
            // (read from original, read from encrypted, read from decrypted).
            var encryptedStream = asymmetricProvider.EncryptedStream(streamSample);
            var decryptedStream = asymmetricProvider.DecryptedStream(encryptedStream);

            byte[] result = new byte[sampleStreamSize];
            decryptedStream.Read(result, 0, result.Length);

            Assert.IsTrue(
                result.SequenceEqual(streamSample.ToArray()),
                "Decrypted data does not match original data");
        }
        public void ToKeyFileStringPublicOnlyCertificateTest()
        {
            // Load Certificate
            X509Certificate2 cert = new X509Certificate2("4096.pfx", string.Empty, X509KeyStorageFlags.Exportable);

            // Make a provider
            AsymmetricBlobCryptoProvider asymmetricProvider = new AsymmetricBlobCryptoProvider(cert, true);

            string keyString = asymmetricProvider.ToKeyFileString(true);

            // Clone a new provider from exported keyfile
            IBlobCryptoProvider clonedProvider = ProviderFactory.CreateProviderFromKeyFileString(keyString);

            // Run an encryption loop using the two providers
            // Should be able to encrypt with the public only clone, and decrypt with the original
            var encryptedStream = clonedProvider.EncryptedStream(streamSample);
            var decryptedStream = asymmetricProvider.DecryptedStream(encryptedStream);

            byte[] result = new byte[sampleStreamSize];
            decryptedStream.Read(result, 0, result.Length);

            Assert.IsTrue(
                result.SequenceEqual(streamSample.ToArray()),
                "Decrypted data does not match original data");
        }