find a location for property in a new city

Friday, 18 May 2012

How to get Azure storage Account Key from a CloudStorageAccount object

I have a CloudStorageAccount object and I want to get the AccountKey out of it. Seems like you should be able to get the Cloud Storage Key out of a CloudStorageAccount but I did struggle a bit at first.

I first used the CloudStorageAccount.FromConfigurationSetting(string) method at first and then played about in debug mode to see if I could find it.

I then found that that method doesn't return the correct type of object which left me unable to find my Azure storage access key. I then tried the same thing but using CloudStorageAccount.Parse(string) instead. This did have access to the Azure storage access key.

//this method of getting your CloudStorageAccount is no good here
//var account = CloudStorageAccount.FromConfigurationSetting("StorageConnectionStr");

//these two lines do...
var accountVal = RoleEnvironment.GetConfigurationSettingValue("StorageConnectionStr");
var account = CloudStorageAccount.Parse(accountVal);

//and then you can retrieve the key like this:
var key = ((StorageCredentialsAccountAndKey)account.Credentials)
          .Credentials.ExportBase64EncodedKey();

It is strange that CloudStorageAccount.FromConfigurationSetting doesn't give you access to the account key in your credentials but CloudStorageAccount.Parse does. Oh well, hope that helps.

Follow britishdev on Twitter

5 comments:

  1. I have an .net app that we currently license to hardware - motherboard make, BIOS etc etc etc, is there any Unique Id for azure I can tie this to, or if you would know of a secure way I can license this SW without hardware, SW is written in C# - I currently have EC2 in Amazon Cloud sorted because every time I rebooted the instance the fingerprint for the license was then mismatched, I also need AZURE on the list as this will be the same, do you know what others are doing to license their software on these cloud platforms, sorry if this is not the right area for this question - I have been "googling till my head hurts" - any advice on where I could find this info would be appreciated, thanks, Simon - NZ

    ReplyDelete
  2. I really believe you will do much better in the future I appreciate everything you have added to my knowledge base. Admiring the time and effort you put into your blog and detailed information you offer!
    http://celabright.com/

    ReplyDelete
  3. Considerably the article is in reality the greatest on this noteworthy topic. I agree with your conclusions and will eagerly look forward to your next updates. Saying thanks will not just be sufficient for the wonderful clarity in your writing. I will immediately grab your rss feed to stay privy of any updates! http://scarprinnow.com

    ReplyDelete
  4. Thanks for taking the time to discuss this I feel strongly about it and love learning more on this topic. If possible as you gain expertise would you mind updating your blog with more information? as it is extremely helpful for me.
    www.fadeplex.com

    ReplyDelete