1

I have an Azure storage connection string and from which I want to read AccountName and Account Key.
I could get the account Name but not the key.
Can anyone suggest me how to read Key?

ConnectionString : DefaultEndpointsProtocol=https;AccountName=dev;AccountKey=tsdsgyduysaugdsay4aR6EPn2Ie9YOILeEp5RRFXeeaJ9;EndpointSuffix=core.windows.net

var cloudStorageAccount = CloudStorageAccount.Parse(ConnectionString);

var storageCredentials = new StorageCredentials(cloudStorageAccount.Credentials.AccountName, cloudStorageAccount.Credentials.KeyName);
7
  • 1
    Why do you need this? Once you have an instance of CloudStorageAccount, you can perform all storage operations. Commented Apr 20, 2019 at 10:47
  • I want to create CloudBlockBlob object with fileUri and storage credentials Commented Apr 20, 2019 at 10:50
  • I think it will not be presented because it would lay in memory for no reason. Normally the key is part of the connection string or is put to the config. Would be good to know what you want to achieve here. Commented Apr 20, 2019 at 10:50
  • Just use cloudStorageAccount.CreateCloudBlobClient() and so on. learn.microsoft.com/en-us/azure/storage/blobs/… Commented Apr 20, 2019 at 10:52
  • How can I do GetBlockBlobReference with full URL? Commented Apr 20, 2019 at 11:03

2 Answers 2

1

So if you have storage credentials (account name and key) and the blob's URI, there're two ways to create an instance of CloudBlockBlob.

        var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key;EndpointSuffix=core.windows.net;");
        var blob = new CloudBlockBlob(new Uri("https://account-name.blob.core.windows.net/container-name/blob-name"), storageAccount.Credentials);

OR

        var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key;EndpointSuffix=core.windows.net;");
        var blobClient = storageAccount.CreateCloudBlobClient();
        var blob = new CloudBlockBlob(new Uri("https://account-name.blob.core.windows.net/container-name/blob-name"), blobClient);
Sign up to request clarification or add additional context in comments.

Comments

0

I had the same issue, you need to use the ExportBase64EncodedKey() method to extract the key and even then it's hidden from debug:

var storageAccount = CloudStorageAccount.Parse(_connectionString);
var credential = new StorageSharedKeyCredential(storageAccount.Credentials.AccountName, storageAccount.Credentials.ExportBase64EncodedKey());    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.