Skip to main content

Python Easy RSA 是一个包装器,它允许更简单的解密、加密、签名和验证签名。您可以从文件或字符串中加载密钥。它易于使用,快速且免费!

项目描述

Python 简易 RSA

上传 Python 包

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.tar.gz (4.6 kB 查看哈希

已上传 source

内置分布

python_easy_rsa-1.0.1-py3-none-any.whl (4.3 kB 查看哈希

已上传 py3