生成Azure存储访问SAS的疑问:为何需使用Event Hub的SAS Token生成代码?
Great question! Let me break this down in plain terms:
SAS tokens are tied to specific Azure services
Azure Storage (Blob/File/Queue/Table) and Azure Event Hubs are completely separate services, each with their own unique rules for creating valid SAS tokens. ThegenerateSharedAccessSignaturemethod in the Azure Storage Android SDK is purpose-built for Storage resources—it handles the exact parameters, hashing logic, and URI formatting that Storage expects. This method won’t work for Event Hubs, because Event Hubs uses a different signature structure (like targeting namespace or Event Hub resources instead of Storage containers/blobs, and different components in the signature string).SDK convenience vs. manual REST compatibility
The Storage SDK’s method is a handy wrapper: it takes care of all the low-level nitty-gritty (URL encoding, HMAC-SHA256 hashing, timestamp formatting) so you don’t have to write that code from scratch. Meanwhile, the code in the Event Hubs documentation is for scenarios where you might not be using a dedicated SDK—like making direct REST API calls to Event Hubs, or working in an environment where an official SDK isn’t available. In those cases, you need to manually implement the SAS logic to meet Event Hubs’ specific authentication requirements.Pick the right tool for the job
Use the Storage SDK’sgenerateSharedAccessSignaturewhen your Android app interacts with Azure Storage (e.g., uploading images to Blob Storage). Use the manual code from the Event Hubs docs when you need to authenticate requests to Event Hubs (e.g., sending event data from your app to an Event Hub). They’re two tools designed for two distinct Azure services.
内容的提问来源于stack exchange,提问作者Samir Baid

