当前位置: 首页>>代码示例>>C#>>正文


C# StorageCredentials.ExportKey方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Auth.StorageCredentials.ExportKey方法的典型用法代码示例。如果您正苦于以下问题:C# StorageCredentials.ExportKey方法的具体用法?C# StorageCredentials.ExportKey怎么用?C# StorageCredentials.ExportKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Auth.StorageCredentials的用法示例。


在下文中一共展示了StorageCredentials.ExportKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StorageCredentialsSharedKey

        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, Convert.ToBase64String(cred.ExportKey()));
            byte[] dummyKey = { 0, 1, 2 };
            string base64EncodedDummyKey = Convert.ToBase64String(dummyKey);
            cred.UpdateKey(base64EncodedDummyKey, null);
            Assert.AreEqual(base64EncodedDummyKey, Convert.ToBase64String(cred.ExportKey()));

#if !RTMD
            dummyKey[0] = 3;
            base64EncodedDummyKey = Convert.ToBase64String(dummyKey);
            cred.UpdateKey(dummyKey, null);
            Assert.AreEqual(base64EncodedDummyKey, Convert.ToBase64String(cred.ExportKey()));
#endif
        }
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:25,代码来源:CloudStorageAccountTests.cs

示例2: StorageCredentialsNullKeyValue

        public void StorageCredentialsNullKeyValue()
        {
            string accountName = TestBase.TargetTenantConfig.AccountName;
            string keyValue = TestBase.TargetTenantConfig.AccountKey;
            string nullKeyValueAsString = null;

            TestHelper.ExpectedException<ArgumentNullException>(() =>
            {
                StorageCredentials credentials1 = new StorageCredentials(accountName, nullKeyValueAsString);
            }, "Cannot create key with a null value.");

            StorageCredentials credentials2 = new StorageCredentials(accountName, keyValue);
            Assert.AreEqual(accountName, credentials2.AccountName);
            Assert.IsFalse(credentials2.IsAnonymous);
            Assert.IsFalse(credentials2.IsSAS);
            Assert.IsTrue(credentials2.IsSharedKey);
            Assert.AreEqual(keyValue, Convert.ToBase64String(credentials2.ExportKey()));

            TestHelper.ExpectedException<ArgumentNullException>(() =>
            {
                credentials2.UpdateKey(nullKeyValueAsString, null);
            }, "Cannot update key with a null string value.");

#if !WINDOWS_RT
            byte[] nullKeyValueAsByteArray = null;

            StorageCredentials credentials3 = new StorageCredentials(accountName, keyValue);
            Assert.AreEqual(accountName, credentials3.AccountName);
            Assert.IsFalse(credentials3.IsAnonymous);
            Assert.IsFalse(credentials3.IsSAS);
            Assert.IsTrue(credentials3.IsSharedKey);
            Assert.AreEqual(keyValue, Convert.ToBase64String(credentials3.ExportKey()));

            TestHelper.ExpectedException<ArgumentNullException>(() =>
            {
                credentials3.UpdateKey(nullKeyValueAsByteArray, null);
            }, "Cannot update key with a null byte array value.");
#endif
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:39,代码来源:CloudStorageAccountTests.cs

示例3: StorageCredentialsEmptyKeyValue

        public void StorageCredentialsEmptyKeyValue()
        {
            string accountName = TestBase.TargetTenantConfig.AccountName;
            string keyValue = TestBase.TargetTenantConfig.AccountKey;
            string emptyKeyValueAsString = string.Empty;
            string emptyKeyConnectionString = string.Format(CultureInfo.InvariantCulture, "DefaultEndpointsProtocol=https;AccountName={0};AccountKey=", accountName);

            StorageCredentials credentials1 = new StorageCredentials(accountName, emptyKeyValueAsString);
            Assert.AreEqual(accountName, credentials1.AccountName);
            Assert.IsFalse(credentials1.IsAnonymous);
            Assert.IsFalse(credentials1.IsSAS);
            Assert.IsTrue(credentials1.IsSharedKey);
            Assert.AreEqual(emptyKeyValueAsString, Convert.ToBase64String(credentials1.ExportKey()));

            CloudStorageAccount account1 = new CloudStorageAccount(credentials1, true);
            Assert.AreEqual(emptyKeyConnectionString, account1.ToString(true));
            Assert.IsNotNull(account1.Credentials);
            Assert.AreEqual(accountName, account1.Credentials.AccountName);
            Assert.IsFalse(account1.Credentials.IsAnonymous);
            Assert.IsFalse(account1.Credentials.IsSAS);
            Assert.IsTrue(account1.Credentials.IsSharedKey);
            Assert.AreEqual(emptyKeyValueAsString, Convert.ToBase64String(account1.Credentials.ExportKey()));

            CloudStorageAccount account2 = CloudStorageAccount.Parse(emptyKeyConnectionString);
            Assert.AreEqual(emptyKeyConnectionString, account2.ToString(true));
            Assert.IsNotNull(account2.Credentials);
            Assert.AreEqual(accountName, account2.Credentials.AccountName);
            Assert.IsFalse(account2.Credentials.IsAnonymous);
            Assert.IsFalse(account2.Credentials.IsSAS);
            Assert.IsTrue(account2.Credentials.IsSharedKey);
            Assert.AreEqual(emptyKeyValueAsString, Convert.ToBase64String(account2.Credentials.ExportKey()));

            CloudStorageAccount account3;
            bool isValidAccount3 = CloudStorageAccount.TryParse(emptyKeyConnectionString, out account3);
            Assert.IsTrue(isValidAccount3);
            Assert.IsNotNull(account3);
            Assert.AreEqual(emptyKeyConnectionString, account3.ToString(true));
            Assert.IsNotNull(account3.Credentials);
            Assert.AreEqual(accountName, account3.Credentials.AccountName);
            Assert.IsFalse(account3.Credentials.IsAnonymous);
            Assert.IsFalse(account3.Credentials.IsSAS);
            Assert.IsTrue(account3.Credentials.IsSharedKey);
            Assert.AreEqual(emptyKeyValueAsString, Convert.ToBase64String(account3.Credentials.ExportKey()));

            StorageCredentials credentials2 = new StorageCredentials(accountName, keyValue);
            Assert.AreEqual(accountName, credentials2.AccountName);
            Assert.IsFalse(credentials2.IsAnonymous);
            Assert.IsFalse(credentials2.IsSAS);
            Assert.IsTrue(credentials2.IsSharedKey);
            Assert.AreEqual(keyValue, Convert.ToBase64String(credentials2.ExportKey()));

            credentials2.UpdateKey(emptyKeyValueAsString, null);
            Assert.AreEqual(emptyKeyValueAsString, Convert.ToBase64String(credentials2.ExportKey()));

#if !WINDOWS_RT
            byte[] emptyKeyValueAsByteArray = new byte[0];

            StorageCredentials credentials3 = new StorageCredentials(accountName, keyValue);
            Assert.AreEqual(accountName, credentials3.AccountName);
            Assert.IsFalse(credentials3.IsAnonymous);
            Assert.IsFalse(credentials3.IsSAS);
            Assert.IsTrue(credentials3.IsSharedKey);
            Assert.AreEqual(keyValue, Convert.ToBase64String(credentials3.ExportKey()));

            credentials3.UpdateKey(emptyKeyValueAsByteArray, null);
            Assert.AreEqual(Convert.ToBase64String(emptyKeyValueAsByteArray), Convert.ToBase64String(credentials3.ExportKey()));
#endif
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:68,代码来源:CloudStorageAccountTests.cs


注:本文中的Microsoft.WindowsAzure.Storage.Auth.StorageCredentials.ExportKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。