title: Encrypting/Decrypting JWE with Jose in Go
body: <p>I'm trying to create a JWE decryption function but having trouble determining how to use the Go Jose interface for doing so. I've factored the encryption using passphrase (I prefer a passphrase for this use case):</p>
  
  <pre><code>    token := jwt.NewWithClaims(
          jwt.SigningMethodHS256,
          claims,
      )
      ss, err := token.SignedString("thisisatestpassphraserighthere")
      if err != nil {
          panic("COULD_NOT_GENERATE")
          return
      }
      privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
      if err != nil {
          panic(err)
      }
      publicKey := &amp;privateKey.PublicKey
      encrypter, err := jose.NewEncrypter(
          jose.A128CBC_HS256,
          jose.Recipient{Algorithm: jose.RSA_OAEP, Key: publicKey},
          nil,
      )
      if err != nil {
          return
      }
      object, err := encrypter.Encrypt([]byte(ss))
      if err != nil {
          errRes = s.Error(codes.Internal, err, nil)
          return
      }
      key, err := object.CompactSerialize()
      if err != nil {
          errRes = s.Error(codes.Internal, err, nil)
          return
      }
      fmt.Println(key)
  </code></pre>
  
  <p>The above code creates a JWT, encodes it, compacts it and returns the key. It's not however totally clear how to decrypt it with the passphrase now.</p>
  
  <p>There is an example for JWE on the Jose docs: <a href="https://godoc.org/gopkg.in/square/go-jose.v2#example-Encrypter--Encrypt" rel="nofollow noreferrer">https://godoc.org/gopkg.in/square/go-jose.v2#example-Encrypter--Encrypt</a></p>
  
  <p>So I've factored this:</p>
  
  <pre><code>    object, err = jose.ParseEncrypted(Key)
      if err != nil {
          panic(err)
      }
      decrypted, err := object.Decrypt(...)
  </code></pre>
  
  <p>Inside the ellipses I'm not sure what to put though. I can't seem to determine how to pass in a key based on passphrase.</p>