使用 oauth2client.service_account 和 google.oauth2 使用私钥签名的区别

问题描述

我正在尝试将我的 Google Cloud Storage 网址签名函数更新为 V4。 Google 为此提供了一个模板,我想我会遵循它直到 https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/signed_urls/generate_signed_urls.py#L112

#signer.sign() signs using RSA-SHA256 with PKCS1v15 padding
signature = binascii.hexlify(
    google_credentials.signer.sign(string_to_sign)
).decode()

我目前使用的是 V2 和 oauth2client 库。目前的代码片段是:

    creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_creds)
    signature = binascii.hexlify(creds.sign_blob(string_to_sign)[1]).decode()

但这似乎不起作用,因为我收到签名错误。我试图推理这两种签名方法间的不同之处,但我遇到了麻烦。 https://oauth2client.readthedocs.io/en/latest/_modules/oauth2client/service_account.html#ServiceAccountCredentials.sign_blob

google.oauth2 https://google-auth.readthedocs.io/en/latest/reference/google.auth.crypt.rsa.html

文档中的 RSA 模块中似乎没有文档

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)