1. 程式人生 > >RSA加密的python實現

RSA加密的python實現

import rsa
key = rsa.newkeys(3000)#生成隨機祕鑰
privateKey = key[1]#私鑰
publicKey = key[0]#公鑰
message ='sanxi Now is better than never.'
print('Before encrypted:',message)
message = message.encode()
cryptedMessage = rsa.encrypt(message, publicKey)
print('After encrypted:\n',cryptedMessage)
message = rsa.decrypt(cryptedMessage, privateKey)
message = message.decode()
print('After decrypted:',message)