python加密解密怎么样将unicode码加30,Python的加解密函数给了我一个unicode

编程入门 行业动态 更新时间:2024-10-06 06:47:06

python加密解密怎么样将unicode码加30,Python的加解密函数<a href=https://www.elefans.com/category/jswz/34/1696603.html style=给了我一个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

本文发布于:2024-02-27 21:26:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1766320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:给了   函数   加密解密   加解密   我一个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!