title: How to create PKCS#8 Private Key using Go
body: <p>I want to generate tls certificates.</p>
  
  <p>So first I need a Private Key.</p>
  
  <pre><code>-----BEGIN PRIVATE KEY-----
  BASE64 ENCODED DATA
  -----END PRIVATE KEY-----
  </code></pre>
  
  <p>But, I can generate <em>RSA</em> Private Key</p>
  
  <pre><code>// "crypto/rsa"
  rsa.GenerateKey(cryptorand.Reader, 2048)
  </code></pre>
  
  <p>which gives me following</p>
  
  <pre><code>-----BEGIN RSA PRIVATE KEY-----
  BASE64 ENCODED DATA
  -----END RSA PRIVATE KEY-----
  </code></pre>
  
  <p>And I can't use it. I need <code>PKCS#8</code> Private Key start with <code>BEGIN PRIVATE KEY</code></p>
  
  <p>How can I generate <code>PKCS#8</code> Private Key?</p>
  
  <p>Or Is there any way to convert <code>PKCS#1</code> to <code>PKCS#8</code> Key?</p>