public void StorageCredentialsSharedKey()
        {
            StorageCredentials cred = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, TestBase.TargetTenantConfig.AccountKey);

            Assert.AreEqual(TestBase.TargetTenantConfig.AccountName, cred.AccountName, false);
            Assert.IsFalse(cred.IsAnonymous);
            Assert.IsFalse(cred.IsSAS);
            Assert.IsTrue(cred.IsSharedKey);

            Uri testUri = new Uri("http://test/abc?querya=1");
            Assert.AreEqual(testUri, cred.TransformUri(testUri));

            Assert.AreEqual(TestBase.TargetTenantConfig.AccountKey, cred.ExportBase64EncodedKey());
            byte[] dummyKey = { 0, 1, 2 };
            string base64EncodedDummyKey = Convert.ToBase64String(dummyKey);
            cred.UpdateKey(base64EncodedDummyKey);
            Assert.AreEqual(base64EncodedDummyKey, cred.ExportBase64EncodedKey());

#if !WINDOWS_RT
            dummyKey[0] = 3;
            base64EncodedDummyKey = Convert.ToBase64String(dummyKey);
            cred.UpdateKey(dummyKey);
            Assert.AreEqual(base64EncodedDummyKey, cred.ExportBase64EncodedKey());
#endif
        }
Esempio n. 2
0
 /// <summary>
 /// Determines whether an other <see cref="StorageCredentials"/> object is equal to this one by comparing their SAS tokens, account names, key names, and key values.
 /// </summary>
 /// <param name="other">The <see cref="StorageCredentials"/> object to compare to this one.</param>
 /// <returns><c>true</c> if the two <see cref="StorageCredentials"/> objects are equal; otherwise, <c>false</c>.</returns>
 public bool Equals(StorageCredentials other)
 {
     if (other == null)
     {
         return(false);
     }
     else
     {
         return(string.Equals(this.SASToken, other.SASToken) &&
                string.Equals(this.AccountName, other.AccountName) &&
                string.Equals(this.KeyName, other.KeyName) &&
                string.Equals(this.ExportBase64EncodedKey(), other.ExportBase64EncodedKey()));
     }
 }
 /// <summary>
 /// Determines whether an other <see cref="StorageCredentials"/> object is equal to this one by comparing their SAS tokens, account names, key names, and key values.
 /// </summary>
 /// <param name="other">The <see cref="StorageCredentials"/> object to compare to this one.</param>
 /// <returns><c>true</c> if the two <see cref="StorageCredentials"/> objects are equal; otherwise, <c>false</c>.</returns>
 public bool Equals(StorageCredentials other)
 {
     if (other == null)
     {
         return false;
     }
     else
     {
         return string.Equals(this.SASToken, other.SASToken) &&
             string.Equals(this.AccountName, other.AccountName) &&
             string.Equals(this.KeyName, other.KeyName) &&
             string.Equals(this.ExportBase64EncodedKey(), other.ExportBase64EncodedKey());
     }
 }
        // Helper function to allow Storage Client 1.7 (Microsoft.WindowsAzure.Storage) to utilize this class.
        // Remove this function if only using Storage Client 2.0 (Microsoft.WindowsAzure.Storage).
        public void DownloadBlobAsync(Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob, string LocalFile)
        {
            Microsoft.WindowsAzure.Storage.Auth.StorageCredentials account = blob.ServiceClient.Credentials as Microsoft.WindowsAzure.Storage.Auth.StorageCredentials;
            ICloudBlob blob2 = new Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob(blob.Uri, new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(blob.ServiceClient.Credentials.AccountName, account.ExportBase64EncodedKey()));

            DownloadBlobAsync(blob2, LocalFile);
        }