对象存储OBSURL中携带签名_URL中携带签名
生(sheng)成签名
1. 准备参数

操作:GETObject

路径:/examplebucket/exampleobject

时间戳:20220101T00:00:00Z
密钥:youraccesskeyid
2. 生(sheng)成签名
使用HMACSHA256算法,名U名(ming)将上述参数进(jin)行拼接,对象带签带签然后计算签名。存(cun)储
(图片来源网络,中携中(zhong)携侵删)import hmacimport hashlibimport base64def generate_signature(secret_key, string_to_sign): signature = base64.b64encode(hmac.new(str(secret_key).encode('utf8'), str(string_to_sign).encode('utf8'), hashlib.sha256).digest()) return signature.decode()secret_key = 'youraccesskeyid'string_to_sign = 'GET20220101T00:00:00Z/examplebucket/exampleobject'signature = generate_signature(secret_key, string_to_sign)构建带签名的URL
将签名添加到URL中,形成带签名的(de)URL。
url = f'https://obs.example.com/examplebucket/exampleobject?Signature={ signature}&Expires={ expiration_time}'使用带签名的URL访问对象
通过浏览器或其他HTTP客户端,使用带签名的URL访问OBS中的对象。
import requestsresponse = requests.get(url)print(response.text)注意事项
确(que)保签名算法和参数与OBS服务的设置一致。
保护好密钥,避免泄露。
| 序号 | OBS对象Key | 签名(ming)前URL | 签名后URL | 签名有效时间 |
| 1 | example.jpg | http://obs.example.com/example.jpg?param=value | http://obs.example.com/example.jpg?param=value&signature=xxxxx | 1小时 |
| 2 | document.pdf | http://obs.example.com/document.pdf | http://obs.example.com/document.pdf?signature=yyyyy | 30分钟 |
| 3 | video.mp4 | http://obs.example.com/videos/video.mp4 | http://obs.example.com/videos/video.mp4?signature=zzzzz | 24小时 |
说明:
序号:记录的序号,方便管理。
OBS对象Key:对象存储中的文件路径或唯一标(biao)识。
签名前(qian)URL:原始的对象存储URL,可能包含一些必要的查询参数。
签名后URL:在原(yuan)始URL后添加了签名参数的URL,通常用于临时授权访问。
签名有效时间:签名的时间限制,超出此时间限制,签名将无效。
signature:通常是通过计算得出的一个字符串,确(que)保请求的合法性和数据的完(wan)整性。
请注意,这里的签名是示例用的,实际签名需要通过具体的(de)加密算法和密钥生成,保证安全性,在(zai)不同的对(dui)象存储服务中,签名的具体实现和参数可能会有所不同。





