Python如何使用模+;指数

Python如何使用模+;指数,python,python-3.x,rsa,python-cryptography,Python,Python 3.x,Rsa,Python Cryptography,你好,我需要用RSA编码文本,使用模和指数+输入 我已经试过了,但是有错误 rsa_modulus = data['publickey_mod'] rsa_exponent = data['publickey_exp'] rsa_timestamp = data['timestamp'] rsa_publickey = rsa.PublicKey(rsa_modulus, rsa_exponent)

你好,我需要用RSA编码文本,使用模和指数+输入

我已经试过了,但是有错误

            rsa_modulus = data['publickey_mod']
            rsa_exponent = data['publickey_exp']
            rsa_timestamp = data['timestamp']
            rsa_publickey = rsa.PublicKey(rsa_modulus, rsa_exponent)
            encrypted = rsa.encrypt(password,rsa_publickey)
            print(encrypted)

AttributeError:“str”对象没有属性“bit\u length”

请尝试对密码进行编码:

encrypted = rsa.encrypt(password.encode('utf8'), rsa_publickey)

rsa.Encrypt
采用字节对象

希望您这样做是为了演示,而不是为了实际的安全关键型应用程序。因为以这种方式仅使用RSA而不使用任何随机填充是不安全的


请看

这里没有人知道
数据
包含什么,我们也无法确定哪一行引发该异常,因此很难提供帮助。事实上,我们也不知道你在用什么加密库。也许您可以添加一些说明。我是否也应该将rsa_公钥传输到byte对象?当我重新创建该问题时,我不需要这样做