У меня есть этот фрагмент скрипта в Python, и я хочу преобразовать его в PowerShell:
method = "GET"
URL = "PeRT RESTful API URL"
contentType = ""
publicAccessKey = "Your Public Access Key"
date = datetime.now().strftime("%a, %d %b %Y %X +0000")
cotentMd5 = ""
secretAccessKey = "Your Secret Access Key"
# URL used to create signature should not include parameters!!!
stringToSign = method + "\n" + url + "\n" + contentType + "\n" + publicAccessKey + "\n" + date + "\n" + cotentMd5
#print(stringToSign)
message = bytes(stringToSign).encode('utf-8')
secret = bytes(secretAccessKey).encode('utf-8')
signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest())
headers = {
"Authorization": publicAccessKey + ":" + signature,
"Date" : date
}
response = requests.get(url, headers=headers)
вот что я написал:
$URL = "PeRT RESTful API URL"
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
publicAccessKey = "Your Public Access Key"
secretAccessKey = "Your Secret Access Key"
$date= Get-Date -Format "ddd, dd MMM yyyy HH:mm:ss +0000"
$stringToSign= "GET" + "`n" + $baseURL + "`n" + "" + "`n" + $publicAccessKey + "`n" + $date + "`n" + ""
$hmacsha.key= [System.Text.Encoding]::ASCII.GetBytes($secretAccessKey)
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($stringToSign))
$signature = [Convert]::ToBase64String($signature)
$headers = @{ "Authorization" = $publicAccessKey + ":" + $signature ; "Date" = $date }
$response = Invoke-RestMethod -Uri $URL -Headers $headers
получение статуса HTTP 401 - Неверный идентификатор клиента или пароль. "
может ли кто-нибудь определить проблему?