title: Rails can't read certificate information from environment due to nested asn1 error
body: <p>I've got some certificate files, namely a .key file which says:</p>
  
  <pre><code>-----BEGIN RSA PRIVATE KEY-----
  IEpAIBAAKCAQEAwAwxt4edIh3UuK8r5
  ....blablabla..................
  QSNoquaasdsaKDybrezemVqCxsQjg==
  -----END RSA PRIVATE KEY-----
  </code></pre>
  
  <p>So it's a RSA Private Key.</p>
  
  <p>I used to load them from files like so:</p>
  
  <pre><code>@private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file))
  </code></pre>
  
  <p>But since I am using Heroku, I intend to have my certificates saved as their values in environment variables.</p>
  
  <p>So I've pasted them in my .env file</p>
  
  <pre><code>COMPANY_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKC.....\n-----END RSA PRIVATE KEY-----"
  </code></pre>
  
  <p>Yeah, I switched the <code>\n</code> for explicits <code>\\n</code> based on <a href="https://stackoverflow.com/questions/6942600/multi-line-config-variables-in-heroku">Multi-line config variables in Heroku</a>. So now my code looks like this:</p>
  
  <pre><code>@private_key = OpenSSL::PKey::RSA.new(ENV['COMPANY_KEY'])
  </code></pre>
  
  <p>And if I run it from the console I get the object built. But if I try to run it from the web server (Puma 3.4.0 over Rails 4.2.6, Ruby 2.2.3) it fails miserably saying: <strong><em><code>Neither PUB key nor PRIV key:: nested asn1 error</code></em></strong> when trying to run that same line.</p>
  
  <p>If I use the debug console I get that the read file looks like 
  <code>"Line 1\\nLine3\\nLinea3"</code> and so on...</p>
  
  <p>I'm pretty sure that it has something to do with the file format, but I'm all out of ideas and maybe you could help if you had a problem like mine.</p>