public void ToKeyFileStringDecryptFailsWithNoPrivateKeyTest()
        {
            // 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 cloned provider
            // which should not have a private key (And thus fail).
            var encryptedStream = clonedProvider.EncryptedStream(streamSample);
            var decryptedStream = clonedProvider.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");
        }
     public async static Task UploadFromStreamEncryptedAsync(this ICloudBlob blob, IBlobCryptoProvider provider, Stream stream,
 AccessCondition accessCondition = null, BlobRequestOptions options = null,
 OperationContext operationContext = null)
     {
         using (Stream encryptedStream = provider.EncryptedStream(stream))
         {
             await blob.UploadFromStreamAsync(encryptedStream, accessCondition, options, operationContext);
         }
     }
 public async static Task UploadFromStreamEncryptedAsync(this ICloudBlob blob, IBlobCryptoProvider provider, Stream stream,
                                                         AccessCondition accessCondition   = null, BlobRequestOptions options = null,
                                                         OperationContext operationContext = null)
 {
     using (Stream encryptedStream = provider.EncryptedStream(stream))
     {
         await blob.UploadFromStreamAsync(encryptedStream, accessCondition, options, operationContext);
     }
 }
     public async static Task UploadFromFileEncryptedAsync(this ICloudBlob blob, IBlobCryptoProvider provider, string path, FileMode mode,
 AccessCondition accessCondition = null, BlobRequestOptions options = null,
 OperationContext operationContext = null)
     {
         using (FileStream fileStream = new FileStream(path, mode))
         using (Stream encryptedStream = provider.EncryptedStream(fileStream))
         {
             await blob.UploadFromStreamAsync(encryptedStream, accessCondition, options, operationContext);
         }
     }
 public async static Task UploadFromFileEncryptedAsync(this ICloudBlob blob, IBlobCryptoProvider provider, string path, FileMode mode,
                                                       AccessCondition accessCondition   = null, BlobRequestOptions options = null,
                                                       OperationContext operationContext = null)
 {
     using (FileStream fileStream = new FileStream(path, mode))
         using (Stream encryptedStream = provider.EncryptedStream(fileStream))
         {
             await blob.UploadFromStreamAsync(encryptedStream, accessCondition, options, operationContext);
         }
 }