title: Writing RSA PrivateKey PEM to file in golang
body: <p>I'm using <a href="https://godoc.org/github.com/spacemonkeygo/openssl" rel="nofollow">spacemonkeygo's openssl library</a> to generate an RSA PrivateKey - the library also offers ways to load a private key from a PEM, but I can't figure out how to turn the private key into an encrypted PEM block - anyone got any ideas?</p>
  
  <pre><code>import "github.com/spacemonkeygo/openssl"
  
  // Generate a private key
  privateKey, _ := openssl.GenerateRSAKey(2048)
  
  password := "an encryption password"
  // Create an encrypted PEM block from the private key?
  pem := ???
  
  // Load the PEM file
  loadedPrivateKey, _ := openssl.LoadPrivateKeyFromPEMWidthPassword(pem, password)
  
  privateKey == loadedPrivateKey
  </code></pre>