要使用 Python 进行 Base64 解密,可以使用 base64 库中的 b64decode() 函数。下面是一个简单的示例代码:

import base64

# 要解密的 Base64 字符串
base64_string = 'SGVsbG8gd29ybGQ='

# 解密
decoded_bytes = base64.b64decode(base64_string)
decoded_string = decoded_bytes.decode('utf-8')

print(decoded_string)

在上面的代码中,我们首先导入 base64 库。然后,我们定义了一个 Base64 字符串 base64_string。接下来,我们使用 b64decode() 函数对字符串进行解密,得到解密后的字节流 decoded_bytes。最后,我们使用 decode() 函数将字节流转换为字符串,并打印输出。

运行上述代码,将输出解密后的字符串 Hello world。请注意,如果 Base64 字符串无效,或者解密后的字节流无法转换为有效的字符串,将引发 UnicodeDecodeError 异常。


原文地址: https://www.cveoy.top/t/topic/o7eJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录