[英]How to access Azure Storage Table using REST API (ARM)
通過查看以下鏈接,尚不清楚簽名應包含哪些內容或如何形成規范的字符串來創建可以使用HMAC-SH256算法加密的簽名。
https://msdn.microsoft.com/zh-CN/library/azure/dd179428.aspx
我正在使用以下網址
獲取https://mystorageaccount.table.core.windows.net/Tables
標頭:
Authorization SharedKeyLite mystorrageaccount:<<encrypted signature>>
x-ms-date Thu 28 Jul 2016 11:19:33 GMT
出現以下錯誤:
服務器無法驗證請求。 確保包括簽名在內的Authorization標頭的值正確形成。
@Prit,請參閱下面的代碼以生成表存儲的共享密鑰lite作為參考。
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
String secret = "<storage-account-key>";
// Date for string to sign
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = sdf.format(calendar.getTime());
// canonicalizedResource, such as "/testaccount1/Tables"
String canonicalizedResource = "<Canonicalized-Resource>";
String stringToSign = date + "\n" + canonicalizedResource;
System.out.println(stringToSign);
// HMAC-SHA@%^
Mac sha256HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
sha256HMAC.init(secretKey);
String hash = Base64.encodeBase64String(sha256HMAC.doFinal(stringToSign.getBytes()));
System.out.println(hash);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.