给了我一个unicode"/>
python加密解密怎么样将unicode码加30,Python的加解密函数给了我一个unicode
下面是我为正在编写的python密钥管理库创建的一些加密和解密函数。在def generate_RSA():
bits = 2048
new_key = RSA.generate(bits)
public_key = new_key.publickey()
private_key = new_key
return private_key, public_key
def encrypt_data(in_fd, chunk_size, pub_key):
encryptor = PKCS1_OAEP.new(pub_key)
A = list()
with open(in_fd, 'rb') as in_file:
while True:
chunk = in_file.read(chunk_size)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += b' ' * (16 - len(chunk) % 16)
encrypted_file = encryptor.encrypt(chunk)
return encrypted_file
def decrypt_data(in_fd, chunk_size, priv_key):
decryptor = PKCS1_OAEP.new(priv_key)
with open(in_fd, 'rb') as in_file:
while True:
chunk = in_file.read(chunk_size)
if len(chunk) == 0:
break
decrypted_file = decryptor.decrypt(eval(str(chunk)))
return decrypted_file
如果需要的话,我希望能够将encrypt_数据和decrypt_数据作为第一个参数相互插入。但是我遇到了一个问题。在
^{pr2}$
每当我尝试运行最后一行代码时,都会得到以下回溯。。。在Traceback (most recent call last):
File "C:\Users\cowbo\source\repos\Python Practice\PythonPractice\FileCounter.py", line 57, in
print(decrypt_data(encrypt_data('C:\\Users\cowbo\OneDrive\Documents\EWC\Haiku.txt', 8192, pub_key), 8192, priv_key))
File "C:\Users\cowbo\source\repos\Python Practice\Python Practice\FileCounter.py", line 31, in decrypt_data
with open(in_fd, 'rb') as in_file:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfd in position 1: invalid start byte
我看了其他关于这个问题的帖子,我似乎加密和解密正确,所以我不确定是什么问题。在
更多推荐
python加密解密怎么样将unicode码加30,Python的加解密函数给了我一个unicode
发布评论