Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
Creating a Shared access Signature without using SDK methods.

Beantwortet Creating a Shared access Signature without using SDK methods.

  • 17 июля 2012 г. 5:23
     
      С кодом

    Hi all,

    I am trying to create SAS signature for Blob without using SDK. I am getting a wrong signature which gives me "403" error with the message "Invalid signature".Can anyone help me in fixing the code. I am sharing the codesnippet i have used below.</p><p></p>

    public static string MakeBlobSignature(CloudStorageAccount Cloudaccount,DateTime starttime, DateTime endtime, string container, string blobname) { string stringtosign = string.Format("w\n{0:yyyy-MM-ddTHH:mm:ssZ}\n{1:yyyy-MM-ddTHH:mm:ssZ}\n/{2}/{3}/{4}\n{5}", starttime, endtime, Cloudaccount.Credentials.AccountName, container, blobname, string.Format("2012-02-12", "yyyy-MM-dd")); return Cloudaccount.Credentials.ComputeHmac(stringtosign); }

    Creating Url through the code below:

    var uri = new UriBuilder(); uri.Scheme = "https"; uri.Host = string.Format("{0}", container.Uri.Host); uri.Path = string.Format("files/{0}", BlobName); uri.Query = string.Format("sv=2012-02-12&st={0}&se={1}&sr=b&sp=w&sig={2}", Uri.EscapeDataString(starttime.ToString("yyyy-MM-ddTHH:mm:ssZ")), Uri.EscapeDataString(endtime.ToString("yyyy-MM-ddTHH:mm:ssZ")), Uri.EscapeDataString(MakeBlobReadSignature(account, starttime, endtime, "files",BlobName))); SasURL = uri.ToString();

    Thanks

    -VIJAY.



Все ответы

  • 17 июля 2012 г. 6:14
     
     Отвечено

    At a quick glance, I'd say your string-to-sign is missing a "signed identifier." I assume you don't have one, and I assume the string should contain a blank line there. Try adding a \n before {5}.

    What does string.Format("2012-02-12", "yyyy-MM-dd") do? Does it return "2012-02-12"? Either way, try just putting "2012-02-12" there.

    What does your final URL look like? How does it compare to the URL created if you use the SDK to create the SAS with the same parameters? If they differ in anything other than the actual signature, try fixing the difference. If it's just the signature, hopefully one of the suggestions above helps.

    If none of this helps, try posting a complete code sample. (E.g., what are the values for starttime and endtime? Where's the call where you're actually using the URL?)

    • Помечено в качестве ответа VIJAYAMANIKANDAN 17 июля 2012 г. 6:39
    •  
  • 17 июля 2012 г. 6:29
     
     

    Hi Steve,

    I added \n before {5} and it is working fine. Thank you so much.


     Thanks! VIJAY.