首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为何我使用.Net API 生成的临时密钥无法进行文件操作?

为何我使用.Net API 生成的临时密钥无法进行文件操作?

提问于 2019-09-16 02:02:11
回答 1关注 0查看 440

我在.Net中使用以下页面提供的API所生成的临时密钥无法操作我的bucket。 API为NuGet中安装的Tencent Cloud API 3.0 SDK for .NET

获取云COS临时密钥:

https://console.cloud.tencent.com/api/explorer?Product=ms&Version=2018-04-08&Action=CreateCosSecKeyInstance&SignVersion=

尝试了使用在上述页面在线调用API生成的临时ID和Key,无法用于以下在线工具的上传文件操作:

对象存储 - Object基本操作 - Put Object:

https://console.cloud.tencent.com/api/explorer?Product=cos&Version=2018-11-26&Action=PutObject&SignVersion=

而且我发现该API提供的临时密钥方法似乎存在bug:

这是我生成临时密钥的方法:

Credential cred = new Credential

{

SecretId = secretId,

SecretKey = secretKey

};

ClientProfile clientProfile = new ClientProfile();

HttpProfile httpProfile = new HttpProfile();

httpProfile.Endpoint = credentialServer;

clientProfile.HttpProfile = httpProfile;

MsClient client = new MsClient(cred, region, clientProfile);

CreateCosSecKeyInstanceRequest req = new CreateCosSecKeyInstanceRequest();

string strParams = "{\"CosRegion\":\"" + region + "\",\"Duration\":" + expireTime + "}";

req = CreateCosSecKeyInstanceRequest.FromJsonString<CreateCosSecKeyInstanceRequest>(strParams);

CreateCosSecKeyInstanceResponse resp = client.CreateCosSecKeyInstance(req).

ConfigureAwait(false).GetAwaiter().GetResult();

string result = AbstractModel.ToJsonString(resp);

return new JsonResult(result);

以上加粗部分的 resp中,CosBucket总是为ms-shield,resp.CosRegion总是为ap-guangzhou,ExpireTime为3600 or 3601 or 3602, resp.CosPrefix总是为pctool/1300222705/20190916/

无论我的传入参数是什么,上述几个属性值为常量。请问这是by design吗?

请问.Net后端该如何正确的生成临时密钥?

相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档