Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

python cryptography

作者:忽然之间   发布日期:2025-11-26   浏览:66

from cryptography.fernet import Fernet

# 生成密钥
key = Fernet.generate_key()

# 创建Fernet对象
cipher_suite = Fernet(key)

# 要加密的文本
plain_text = b"Hello, world!"

# 加密文本
cipher_text = cipher_suite.encrypt(plain_text)
print(f"Encrypted: {cipher_text}")

# 解密文本
decrypted_text = cipher_suite.decrypt(cipher_text)
print(f"Decrypted: {decrypted_text.decode()}")

# 解释说明:
# 1. 使用cryptography库中的Fernet对称加密算法。
# 2. 首先生成一个密钥,该密钥用于加密和解密。
# 3. 使用生成的密钥创建一个Fernet对象。
# 4. 对要加密的文本进行加密,输出加密后的密文。
# 5. 使用相同的密钥对密文进行解密,输出原始明文。

上一篇:python 字符串操作

下一篇:python不换行输出

大家都在看

python时间格式

python读取文件路径

staticmethod在python中有

python开发windows应用程序

python中len是什么意思

python ord和chr

python中的yield

python自定义异常

python判断路径是否存在

python list.pop

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站