I want to test the API of Azure Storage Service with Postman. For that I need a Shared Key which I have to encode before. My problem is, when I try a GET-Request I get an error message I did the steps in the official microsoft documentation: https://docs.microsoft.com/de-de/rest/api/storageservices/authorize-with-shared-key#constructing-the-canonicalized-headers-string
This is my code of the encoding process:
public static String account ="ACCOUNT NAME";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE , dd MMM yyyy HH:mm:ss O");
String date = formatter.format(ZonedDateTime.now(ZoneOffset.UTC));
String stringToSign = "GET\n"
+ "\n" // content encoding
+ "\n" // content language
+ "\n" // content length
+ "\n" // content md5
+ "\n" // content type
+ date +"\n" // date
+ "\n" // if modified since
+ "\n" // if match
+ "\n" // if none match
+ "\n" // if unmodified since
+ "\n" // range
+ "x-ms-date:" + date
+ "\nx-ms-version:2019-07-07\n"
+ "/" + account + "/"
+"\ncomp:list"; // resources
public DirectoryController() throws Exception {
try {
String auth = getAuthenticationString(stringToSign);
System.out.println(auth + date);
}catch (Exception ex) {
throw new Exception();
}
}
private static String getAuthenticationString(String stringToSign) throws Exception {
Mac mac = Mac.getInstance("HmacSHA256");
String key = "KEY";
mac.init(new SecretKeySpec(Base64.decode(key), "HmacSHA256"));
String authKey = new String(Base64.encode(mac.doFinal(stringToSign.getBytes("UTF-8"))));
String auth = "SharedKey " + account + ":" + authKey;
return auth;
}
GET Request; https://ACCOTUNAME.file.core.windows.net/?comp=list
Did I set something wrong in the encoding process. I found out the dateformat is not like microsoft expected. I get Fr. as the day of the week and microsoft wants Fri.. How I get this?