1

I'm trying to call a variable as bytes but I couldn't able to call it, there is a little part of it

 else:
    generated_password = randomString(random_string)
    key = open(input("Please enter your key file"), 'rb').read()
    f = Fernet(key)
    enc_password = f.encrypt(b'generated_password')

Problem its encrypting the name of the variable rather than what it store I quickly look online but couldn't find any related example. If you know how can you please kindly explain?

  • 2
    shouldn't you pass the variable `generated_password` instead of the string? – Rohit Jain Jul 22 '20 at 07:27
  • 1
    Does this answer your question? [Best way to convert string to bytes in Python 3?](https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3) – Putnam Jul 22 '20 at 07:28
  • @RohitJain module just works with bytes when I tried it gives error `TypeError: data must be bytes` –  Jul 22 '20 at 07:51
  • @Putnam It could work thanks for pointing out. –  Jul 22 '20 at 07:54

0 Answers0