[英]Convert base64 encoded google service account key to JSON file using Python
[英]Need a Python code to convert a secret key to base64 encoded
我生成了一个密钥 - A0[Bt"V59.xA-bKO|/A""/Z.!#Y:wfpR ,需要将其转换为 base64 编码格式,请帮助使用 python 代码来执行此操作。
对于 base64 编码,请使用base64
模块及其函数b64encode
。
例子 -
>>> import base64
>>> base64.b64encode("Hello")
'SGVsbG8='
>>> s = 'A0[Bt\"V59.xA-bKO|/A\"\"/Z.!#Y:wfpR'
>>> base64.b64encode(s)
'QTBbQnQiVjU5LnhBLWJLT3wvQSIiL1ouISNZOndmcFI='
对于解码,使用b64decode()
函数 -
>>> import base64
>>> base64.b64decode('SGVsbG8=')
'Hello'
>>> base64.b64decode('QTBbQnQiVjU5LnhBLWJLT3wvQSIiL1ouISNZOndmcFI=')
'A0[Bt"V59.xA-bKO|/A""/Z.!#Y:wfpR'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.