python 实现rsa 的加密解密存读取

xiaoxiao2025-06-14  17

废话不多说直接上代码

import rsa # (pubkey, privkey) = rsa.newkeys(1024) # pub = pubkey.save_pkcs1() # with open('public.pem','wb+')as f: # f.write(pub) # # pri = privkey.save_pkcs1() # with open('private.pem','wb+')as f: # f.write(pri) message = '789'.encode('utf8') with open('public.pem','rb') as publickfile: p = publickfile.read() pubkey = rsa.PublicKey.load_pkcs1(p) # with open('private.pem','rb') as privatefile: p = privatefile.read() privkey = rsa.PrivateKey.load_pkcs1(p) # # # 用公钥加密、再用私钥解密 crypto = rsa.encrypt(message, pubkey) message1 = rsa.decrypt(crypto, privkey) print(message1)
转载请注明原文地址: https://www.6miu.com/read-5031840.html

最新回复(0)