title: Encrypt & Decrypt JWT with any kind of type encryption (AES, etc...) in Golang
body: <p>I am searching for a library in Go that can give to me the capability of crypting for send and decrypting for reading a JWT that I send when a user is logged in my api rest made in Golang. </p>
  
  <p>I have seen a lot of examples with AES, but I have a lot of issues trying to encrypt in AES a JWT because signs like "." or "-" give me problems. </p>
  
  <p>I know that I must use a 32 bytes key, that I can change the base to 64. But only using the most simple example, making a simple hash, using the cipher, I have always the same error at crypting/decrypting. </p>
  
  <p>For instance :</p>
  
  <pre><code>crypto/aes: invalid key size X
  </code></pre>
  
  <p>I use the same code like this Stack Overflow answer :<a href="https://stackoverflow.com/questions/35811119/aes-encryption-golang-and-python">AES Encryption Golang and Python</a></p>
  
  <p>I have already my token signed, I want to add a new level of security after signing.</p>
  
  <pre><code>claims := Claim{
      User: user,
      StandardClaims: djwt.StandardClaims{
          ExpiresAt: time.Now().Add(time.Hour * 1).Unix(),
          Issuer: "App Timer",
      },
  }
  
  token := djwt.NewWithClaims(djwt.SigningMethodRS256, claims)
  result, err := token.SignedString(privateKey)
  
  if err != nil {
      log.Fatal("TokenSingingError")
  }
  </code></pre>