public void ToKeyFileAndBackTest()
        {
            IBlobCryptoProvider asymmetricProvider = new AsymmetricBlobCryptoProvider();

            asymmetricProvider.WriteKeyFile("keyfile.txt");

            IBlobCryptoProvider clonedProvider = ProviderFactory.CreateProviderFromKeyFile("keyfile.txt");

            var encryptedStream = asymmetricProvider.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");
        }
Esempio n. 2
0
        public static void DownloadEncryptedFileSymmetric(string destinationPath, CloudBlobContainer container)
        {
            // Since we have our AES key exported we can use the provider factory to quickly
            // insantiate a provider for working with the key again
            var provider = ProviderFactory.CreateProviderFromKeyFile("symmetricKey.dat");

            // Get a reference to our Blob again
            CloudBlockBlob blob = container.GetBlockBlobReference("SymmetricUploadTest.jpg");

            // Using our 'Encrypted' extension method to download an encrypted file
            // It will be decrypted during download and written to disk ready to use.
            blob.DownloadToFileEncrypted(provider, destinationPath, FileMode.Create);

            // You could instead download without our library, to see how it was stored encrypted in the cloud
            // blob.DownloadToFile(destinationPath, FileMode.Create);

            // Tidy up, delete our blob
            blob.DeleteIfExists();
        }
 public void InvalidPathTest()
 {
     var provider = ProviderFactory.CreateProviderFromKeyFile("invalid.txt");
 }