title: error:0906D06C:PEM routines:PEM_read_bio:no start
body: <p>Getting this very annoying error. <code>error:0906D06C:PEM routines:PEM_read_bio:no start</code></p>
  
  <p>Code:</p>
  
  <pre><code>RSA* publickey = cWrapper.getPublicKey("C:/rsa-stuff/public.pem");
  QByteArray plain = "The man in the black fled into the desert and the gunslinger followed...";
  QByteArray encrypted = cWrapper.encryptRSA(publickey, plain);
  </code></pre>
  
  <p>In encryptRSA():</p>
  
  <pre><code>const char* publicKeyStr = data.constData();
  qDebug() &lt;&lt; publicKeyStr;
  BIO* bio = BIO_new_mem_buf((void*)publicKeyStr, -1);
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  RSA* rsaPubKey = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL);
  if(!rsaPubKey) {
    qDebug() &lt;&lt; "Could not load public key, " &lt;&lt; ERR_error_string(ERR_get_error(), NULL); // error is here
  }
  BIO_free(bio);
  </code></pre>
  
  <p>This is how I read file:</p>
  
  <pre><code>QByteArray data;
  QFile file(filename);
  
  if(!file.open(QFile::ReadOnly))
  {
      printf("Error reading file: %s\n", file.errorString());
      return data;
  }
  
  data = file.readAll();
  file.close();
  return data;
  </code></pre>
  
  <p>When I print out publicKeyStr, looks fine. This is notepad++ view with all characters enabled:
  <a href="https://i.stack.imgur.com/6DB1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6DB1R.png" alt="public key in notepad++"></a></p>
  
  <p>Anyone know what I am doing wrong? Super annoying issue :(</p>
  
  <p>First of all, it's not <a href="https://stackoverflow.com/questions/20837161/openssl-pem-routinespem-read-biono-start-linepem-lib-c703expecting-truste">this</a> problem because I don't get the trusted part. Anyhow, I did try all the "solutions" and none of them worked, same error.</p>