gpt4 book ai didi

c# - Azure 存储连接错误(如果系统时间存在差异)

转载 作者:行者123 更新时间:2023-12-03 06:01:53 25 4
gpt4 key购买 nike

我连接到 Windows Phone 8.1 上的 blob azure 存储。如果请求日期~系统时间,则工作正常。但如果手机上的系统日期有差异...例如1 天...然后总是出错...

public static async Task<AzureDownloadResult> DownloadFileFromBlob(string FileName)
{
using (MemoryStream ms = new MemoryStream())
{
try
{
CloudBlobContainer container = GetBlobClient.GetContainerReference("data");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(FileName);
if (!await blockBlob.ExistsAsync())
{
return new AzureDownloadResult(null, AzureDownloadException.NotExists);
}
long filesize = blockBlob.Properties.Length;
await blockBlob.DownloadToStreamAsync(ms.AsOutputStream());
if (ms.Length != filesize)
{
return new AzureDownloadResult(null, AzureDownloadException.Error);
}
}
catch (Exception e)
{
//<-error there (if i set random time in phone time settings):
//message: ...Make sure the value of Authorization header is formed correctly including the signature..
return new AzureDownloadResult(null, AzureDownloadException.NoneInternetConnectionOrDateTimeError);
}
return new AzureDownloadResult(ms.ToArray(), AzureDownloadException.OK);
}
}

最佳答案

构建所有其他库的 Azure 存储 REST API 使用日期作为请求参数之一,在为请求创建 HMAC 身份验证 token 时提供熵。以下为documented :

The storage services ensure that a request is no older than 15 minutes by the time it reaches the service. This guards against certain security attacks, including replay attacks. When this check fails, the server returns response code 403 (Forbidden).

因此,您应该确保与请求关联的日期时间在该 15 分钟窗口内。

关于c# - Azure 存储连接错误(如果系统时间存在差异),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com