0

Hello i need to encode text with RSA using modulus and exponent + input

I have tried this, but am getting errors

            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' object has no attribute 'bit_length'

Stringsko
  • 23
  • 1
  • 1
  • 7
  • Nobody here has any idea about what `data` contains, nor can we determine which line is raising that exception, so it will be hard to help. In fact, we don't *really* know what crypto library you're using either. Perhaps you can add some clarification. – President James K. Polk Oct 13 '19 at 23:39

2 Answers2

1

Hopefully you are doing this as a demonstration, and not for an actual security critical application. Because using just RSA in this manner without any random padding is not secure.

See How do you encrypt a password by using the RSA Algorithm?

vy32
  • 28,461
  • 37
  • 122
  • 246
0

Try to encode your password:

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

rsa.Encrypt takes a byte object

Joe
  • 462
  • 6
  • 14