title: How to encrypt a variable with the cryptography module?
body: <p>I'm not sure if any of you are familiar with the cryptography module, but I'm trying to encrypt a variable that stands for a string. </p>
  
  <p>For example:</p>
  
  <pre><code>string = input('String here')
  </code></pre>
  
  <p>The example they give on the module page is:</p>
  
  <pre><code>from cryptography.fernet import Fernet
  key = Fernet.generate_key()
  cipher_suite = Fernet(key)
  cipher_text = cipher_suite.encrypt(b"A really secret message. Not for prying eyes.")
  plain_text = cipher_suite.decrypt(cipher_text)
  </code></pre>
  
  <p>Which is all fine and dandy, but when I try and replace the "Really secret message string with a variable, It doesn't work.</p>
  
  <p>If it's in quotes, it just prints the name of the variable(duh)</p>
  
  <p>If it's out of quotes like this: cipher_text = <code>cipher_suite.encrypt(bstring)</code>, it says variable is not defined(also duh)</p>
  
  <p>But if I just put the variable in, it gives me an error: <code>TypeError: data must be bytes.</code></p>
  
  <p>Any ideas? Thanks!</p>