'Getting Cipher Message Authentication Failed

I am creating a middleware function to decrypt the request body of an api call but cannot seem to get it working. The body is encrypted and then base64 encoded before the request is made. Any help would be appreciated.

My curent function code:

            ciphertext, err := ioutil.ReadAll(r.Body)
            if err != nil {
                panic(err.Error())
            }
            ciphertext = decodeBase64(string(ciphertext))

            block, err := aes.NewCipher(keyString)
            if err != nil {
                panic(err.Error())
            }

            aesgcm, err := cipher.NewGCM(block)
            if err != nil {
               panic(err.Error())
            }  

            nonce := make([]byte, aesgcm.NonceSize())
            clearStuff := make([]byte, len(ciphertext))
            plaintext, err := aesgcm.Open(clearStuff, nonce, ciphertext, nil)
            if err != nil {
                panic(err.Error())
            }
            fmt.Println(string(plaintext))

The key is:

var keyString = []byte("ECB518652A170880555136EA1F9752D6")

The error im getting is:

cipher: message authentication failed []

I'm pretty sure that the issue is stemming from ciphertext but I haven't been able to find a solution to the problem. I found a working solution here, but its using the seal to decrypt and that won't be possible in my case. So how can I get this done?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source