RSA加密

import rsa
import  binascii

class MyRSA(object):
    def __init__(self,n,e='10001'):
        #初始化生成公钥
        self.n = int(n,16)
        self.e = int(e,16)
        self.pubkey = rsa.PublicKey(self.n,self.e)

    def encrypt(self,data):
        if isinstance(data,str):
            data = data.encode()
        result = rsa.encrypt(data,self.pubkey)
        return binascii.b2a_hex(result)

if __name__ == "__main__":
    pubkey_n = '8d7e6949d411ce14d7d233d7160f5b2cc753930caba4d5ad24f923a505253b9c39b09a059732250e56c594d735077cfcb0c3508e9f544f101bdf7e97fe1b0d97f273468264b8b24caaa2a90cd9708a417c51cf8ba35444d37c514a0490441a773ccb121034f29748763c6c4f76eb0303559c57071fd89234d140c8bb965f9725'

    r = MyRSA(pubkey_n)
    print(r.encrypt('哈哈哈'))

你可能感兴趣的:(RSA加密)