From 55f53e34ae346cce4baa3a15f2e2cf4fca92388e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 16 Sep 2019 15:20:20 +0800 Subject: [PATCH] bugfix --- appPublic/rsa.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/appPublic/rsa.py b/appPublic/rsa.py index 7630927..0d2a22d 100755 --- a/appPublic/rsa.py +++ b/appPublic/rsa.py @@ -57,11 +57,14 @@ class RSA: ) return key + def publickeyFromText(self,text): + public_key_bytes = bytes(text,encoding='utf8') + return serialization.load_pem_public_key(data=public_key_bytes,backend=default_backend()) + def read_publickey(self,fname): with open(fname,'r') as f: - public_key_pem_export = f.read() - public_key_pem_export = bytes(public_key_pem_export,encoding='utf8') if not isinstance(public_key_pem_export, bytes) else public_key_pem_export - return serialization.load_pem_public_key(data=public_key_pem_export,backend=default_backend()) + text = f.read() + return self.publickeyFromText(text) def create_privatekey(self): return rsa.generate_private_key(