Python 如何使用模数 + 指数对 RSA 进行编码
Python how to encode with RSA using modulus + 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_length'
尝试对您的 password
进行编码:
encrypted = rsa.encrypt(password.encode('utf8'), rsa_publickey)
rsa.Encrypt
取字节对象
希望您这样做是为了演示,而不是针对实际的安全关键应用程序。因为以这种方式仅使用 RSA 而没有任何随机填充是不安全的。
见How do you encrypt a password by using the RSA Algorithm?
你好,我需要使用模数和指数 + 输入用 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_length'
尝试对您的 password
进行编码:
encrypted = rsa.encrypt(password.encode('utf8'), rsa_publickey)
rsa.Encrypt
取字节对象
希望您这样做是为了演示,而不是针对实际的安全关键应用程序。因为以这种方式仅使用 RSA 而没有任何随机填充是不安全的。
见How do you encrypt a password by using the RSA Algorithm?