title: How to generate correct RSA key for signing JWT?
body: <p>I'm using <a href="https://gist.github.com/thealexcons/4ecc09d50e6b9b3ff4e2408e910beb22" rel="nofollow noreferrer">this example</a>, however it is slightly outdated. So, for, example <code>SignedString(key)</code>, I guess, receives <code>*rsa.PublicKey</code> instead of <code>[]byte</code> in case of RS256 signing method. I generated my private key using </p>
  
  <pre><code>openssl genrsa -out key.rsa 1024
  </code></pre>
  
  <p>And now trying to parse it:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "github.com/dgrijalva/jwt-go"
  )
  
  func main() {
      pem := []byte(`-----BEGIN RSA PRIVATE KEY-----
  MIICXQIBAAKBgQCycI9LZT8qM/zCGH0CNxAi7gy7w1YjqZN1N8yFfbmv9toVC82S
  bZDv8NVYVlFNhUbtUFg77TYhHmyPpr4hKqvPrVc0rqVFe4ggQYdXovDgLZhO1MxB
  i4vw9tLRlAK8TYNFqaFiX6lFgRp8trd01GFhkBJMzZCMmBQFkcEgWqT6MQIDAQAB
  AoGBAKSru5GYnfIUh+2XK8YfioSxqo6cdaHznGFQXS3UGMiKxjcl7VB0TI0hc8FR
  5zXjCNF4k/S5tHpb2VO4TT3OYz55/JEOGAXvIMW2UYtL4TwR3+46TRJ95KKowq+c
  3JndjmGjUbvWawtbNklkmgoEkLI8wYu9yss9293GBnff14ABAkEA1scxu0svrIZ1
  R5YmpXOfrtGwsjbdowGNxZTedWlbJukBSNPSIpuUvkzF2PXlPBS80p5yxbYlp1gg
  UhsfXWJwIQJBANSv7lEuHV0QnVVoYVtNijwEHIi7iG7xu7hDQ7bK/kwWV6wqnvfP
  PZopZPDXCRlnxbubo0/RJz4LsaJflDJKiBECQC/3FFgrll4FOTPfiInypHq6QafL
  MPwyYKL7eCLogH7UEoFdLNSlwjYtlxG4+JTOXMz8rc0RvJ7+w1kSzZJhZYECQHMU
  DhqWnQSx7K89nw/L0LPQda/16Eg/O5bjrkvFYfrBTAa3uPPUijxTkW5Oq3m3kGGG
  QML7JASKRz7YAFOFyEECQQCUBNONRYMMzzr4llGOcKISXJtewlOPTHGP++OiHWMB
  rPzZDyi5ONNgySF8t/QnJMTRpRQ5axi0UhojL/OzUt/w
  -----END RSA PRIVATE KEY-----`)
  
      key, err := jwt.ParseRSAPublicKeyFromPEM(pem)
      fmt.Println(key, err)
  }
  </code></pre>
  
  <p>But I get <code>asn1: structure error: tags don't match (16 vs {class:0 tag:2 length:1 isCompound:false}) {optional:false explicit:false application:false defaultValue:&lt;nil&gt; tag:&lt;nil&gt; stringType:0 timeType:0 set:false omitEmpty:false} tbsCertificate @2</code> in response.</p>
  
  <p>Is my key generating command somehow wrong? What should I read to be able to debug this? What asn1 has to do with it? Key has some particular syntax?</p>