title: AttributeError: 'bytes' object has no attribute 'encrypt'
body: <p>I would like to generate an RSA key pair, and then write functions to decrypt using the public key and encrypt using the private key.</p>
  
  <p>At the moment I am generating my keys as follows</p>
  
  <pre><code>from cryptography.hazmat.primitives import serialization as crypto_serialization
  from cryptography.hazmat.primitives.asymmetric import rsa
  from cryptography.hazmat.backends import default_backend as crypto_default_backend
  
  
  key = rsa.generate_private_key(
          backend=crypto_default_backend(),
          public_exponent=65537,
          key_size=2048
      )
  private_key = key.private_bytes(
      crypto_serialization.Encoding.PEM,
      crypto_serialization.PrivateFormat.PKCS8,
      crypto_serialization.NoEncryption())
  public_key = key.public_key().public_bytes(
      crypto_serialization.Encoding.OpenSSH,
      crypto_serialization.PublicFormat.OpenSSH
  )
  </code></pre>
  
  <p>I then followed the cryptography documentation to encrypt with RSA, it says</p>
  
  <pre><code>message = b"encrypted data"
  ciphertext = private_key.encrypt(
      message,
      padding.OAEP(
          mgf=padding.MGF1(algorithm=hashes.SHA256()),
          algorithm=hashes.SHA256(),
          label=None
      )
  )
  </code></pre>
  
  <p>I replaced public_key with private_key.</p>
  
  <p>And to decrypt</p>
  
  <pre><code>plaintext = public_key.decrypt(
      ciphertext,
      padding.OAEP(
          mgf=padding.MGF1(algorithm=hashes.SHA256()),
          algorithm=hashes.SHA256(),
          label=None
      )
  )
  </code></pre>
  
  <p>Here I replaced private_key with public_key.</p>
  
  <p>However, running the encrypt part gives me the error "AttributeError: 'bytes' object has no attribute 'encrypt'".</p>
  
  <p>How can I fix this?</p>