Python Easy RSA 是一个包装器,它允许更简单的解密、加密、签名和验证签名。您可以从文件或字符串中加载密钥。它易于使用,快速且免费!
项目描述
Python 简易 RSA
Python Easy RSA 是一个包装器,它允许更简单的解密、加密、签名和验证签名。您可以从文件或字符串中加载密钥。它易于使用,快速且免费!
生成公钥和私钥
# the directory where the keys are to be stored
# in this case we are using the current file directory
path = Path(__file__).absolute().parent
# initialize the encrypter
encryption = Encryption(path, name=('public_key.pem', 'private1.pem'))
# generates both private and public keys
encryption.generate_keys()
加载现有的私钥和公钥
# the directory where the keys are to be stored
# in this case we are using the current file directory
path = Path(__file__).absolute().parent
# initialize the encrypter
encryption = Encryption(path, name=('public_key.pem', 'private1.pem'))
# loads both private and public keys
encryption.load_keys()
# at this point both public and private keys are loaded in memory
# check example below to encrypt using the load or generate keys
加密消息
# the directory where the keys are to be stored
# in this case we are using the current file directory
path = Path(__file__).absolute().parent
# initialize the encrypter
encryption = Encryption(path, name=('public_key.pem', 'private1.pem'))
# generates or load both private and public keys
encryption.load_keys() # or encryption.generate_keys()
encrypted = encryption.encrypt('hello world')
# return encrypted string
decrypted = encryption.decrypt(encrypted)
# returns a decrypted message
# 'hello world'
使用自定义文件中的自定义密钥进行加密
# one time encryption
# load a public key file
file_content = open('file.pem')
encryption = Encryption()
encrypted = encryption.encrypt('hello world', file_content)
使用自定义文件中的自定义密钥解密
# one time decryption
file_content = open('file.pem')
encryption = Encryption()
encrypted_message = 'somethin encrypted'
decrypted = encryption.decrypt('hello world', file_content)
# returns a decrypted message
签名和验证消息
# loads key from file
encryption = Encryption(path, name=('public_key.pem', 'private1.pem'))
# generates or load both private and public keys
encryption.load_keys() # or encryption.generate_keys()
# sign a string with a private key
hash = encryption.sign('hello world') # or encryption.sign('hello world', private_key_rfrom_file)
# returns a signed hash
# verify if a message is signed by a private key using its counter public key
verified = encryption.verify_sign('hello world', hash) # or encryption.verify_sign('hello world', hash, public_key_from_file)
# returns bool
项目详情
关
python_easy_rsa-1.0.1- py3 -none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fce485dc7a334d58c02d04e315490a051bd755d2db03c6c2edb0d1ad221377d9 |
|
MD5 | 18828ab796c294f772630566dfe4dcfc |
|
布莱克2-256 | 4949044c29986b5563c7557c48dd97576d41d94a2536d77de16702b2f589ae58 |