Как авторизоваться с помощью общего ключа, используя vba и c# com видимый класс - PullRequest
0 голосов
/ 15 апреля 2020

Код VBA создает 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 + "/" + 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));

        '    }


Но, azure возвращает:

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.

, даже если я добавил «text / plain» в StringToSign.

Кто-нибудь знает причину?

...