利用實現rsa加密

import rsa
from rsa.transform import bytes2int


class PasswordEncrypt:
    def __init__(self):
        self.public_key = None
        self.private_key = None

    def set_public_key(self, modules, exponent):
        self.public_key = rsa.PublicKey(int(modules, 16), int(exponent, 16))

    def encrypt(self, message):
        block = rsa.encrypt(message.encoding('utf-8'), self.public_key)
        return hex(bytes2int(block))[2:]


if __name__ == '__main__':
    ras = PasswordEncrypt()
    WEB_PUBLIC_KEY = "dkyyh56445ykff"
    ENCRYPTION_EXPONENT = "10001"
    ras.set_public_key(WEB_PUBLIC_KEY, ENCRYPTION_EXPONENT)
    print(ras.encrypt("888888"))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章