cipher: message authentication failed

I am using crypto/cipher to encrypt and decrypt password. Client encrypts the password and sends to remote server over the network. When the server receives the password, during decryption, error “cipher: message authentication failed” is seen. This issue is seen only when communication is over the network.

Issue is not seen when client and server are running on the same machine.

I am following standard implementation mentioned in https://golang.org/src/crypto/cipher/gcm.go

  • Nonce is of length 12 and new nonce is generated everytime using rand function

  • Encrypt implements " gcm.Seal(nonce, nonce, []byte(passwordStr), nil)"

  • Decrypt implements " gcm.Open(nil, nonce, encrypted, nil)". Error is encountered in this method.

Let me know if anyone else has faced same issue.

1 Like

How are you sending the data from the client to the server?

If you have the issue only when you send the encrypted string over the network perhaps you should care about encoding the data, eg:

I have faced the same issue. @nandinimurthy were you able to resolve? and what did you do?