本文整理汇总了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
}
示例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
}
示例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
}