简体   繁体   English

需要 Python 代码将密钥转换为 base64 编码

[英]Need a Python code to convert a secret key to base64 encoded

我生成了一个密钥 - A0[Bt"V59.xA-bKO|/A""/Z.!#Y:wfpR ,需要将其转换为 base64 编码格式,请帮助使用 python 代码来执行此操作。

For encoding to base64 use the base64 module and its function b64encode for that.对于 base64 编码,请使用base64模块及其函数b64encode

Example -例子 -

>>> import base64
>>> base64.b64encode("Hello")
'SGVsbG8='
>>> s = 'A0[Bt\"V59.xA-bKO|/A\"\"/Z.!#Y:wfpR'
>>> base64.b64encode(s)
'QTBbQnQiVjU5LnhBLWJLT3wvQSIiL1ouISNZOndmcFI='

For decoding , use the b64decode() function -对于解码,使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM