(Solved) – How to Authorize with shared key using vba and c# com visible class

(solved)-–-how-to-authorize-with-shared-key-using-vba-and-c#-com-visible-class

Vba code create StringToSign:

x_ms_date = ASB.UTCTime ‘return Tue, 14 Apr 2020 02:36:28 GMT

StorageAccountName = “MyAccountName”

MyContainer = “MyContainerName”

StorageAccountKey = “MyStorageKey”

StringToSign = “PUT” Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign Chr(10)

StringToSign = StringToSign “x-ms-date:” x_ms_date Chr(10) “x-ms-version:2019-07-07” Chr(10)

StringToSign = StringToSign “https://stackoverflow.com/” StorageAccountName “/” MyContainer Chr(10) “restype:container”

‘Vba code Compute the hash of the SignatureBytes and convert it to a base64 string

‘Vba code reference c# class

CsSignature = ASB.Signature(StringToSign, StorageAccountKey)

{

    '        byte[] SignatureBytes = System.Text.Encoding.UTF8.GetBytes(StringToSign);

    '        System.Security.Cryptography.HMACSHA256 SHA256 = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String(Key));

    '        return Convert.ToBase64String(SHA256.ComputeHash(SignatureBytes));

    '    }

But, azure return:

The MAC signature found in the HTTP request,

is not the same as any computed signature.

i checked server response,still can not figure out.

even if i added “text/plain” to StringToSign.

Does anyone know the reason?

Leave a Reply

Your email address will not be published. Required fields are marked *