title: AES-256-GCM Encryption from Ruby & Decryption with Golang
body: <p>I have an encryption in Ruby with <code>aes-256-gcm</code></p>
  <pre><code>require 'openssl'
  key = &quot;972ec8dd995743d981417981ac2f30db&quot;
  iv = &quot;6a825c25ea74&quot;
  auth_data = &quot;73f6828fc5be&quot;
  plaintext = &quot;John Doe play foo bar&quot;
  
  cipher = OpenSSL::Cipher.new('aes-256-gcm')
  cipher.encrypt
  cipher.iv = iv
  cipher.key = key
  cipher.auth_data = auth_data
  cipherText = cipher.update(plaintext) + cipher.final
  authTag = cipher.auth_tag
  hexString = (cipherText + iv + authTag).unpack('H*').first
  </code></pre>
  <p>the hextString result looks like</p>
  <pre><code>fa03a24cad007ceaadc34c22edff943cb58fe514ed36613832356332356561373425f6bc5724b956daae151c8d78a21263
  </code></pre>
  <p>I want to decrypt it in Go</p>
  <pre><code>key := &quot;972ec8dd995743d981417981ac2f30db&quot;
  iv := &quot;6a825c25ea74&quot;
  authData := &quot;73f6828fc5be&quot;
  hexString, _ := hex.DecodeString(&quot;fa03a24cad007ceaadc34c22edff943cb58fe514ed36613832356332356561373425f6bc5724b956daae151c8d78a21263&quot;)
  
  block, err := aes.NewCipher([]byte(key))
  if err != nil {
      panic(err.Error())
  }
  
  aesgcm, err := cipher.NewGCM(block)
  if err != nil {
      panic(err.Error())
  }
  
  plaintext, err := aesgcm.Open(nil, []byte(iv), hexString, []byte(authData))
  if err != nil {
      panic(err.Error())
  }
  </code></pre>
  <p>I got <code>cipher: message authentication failed</code>.
  and Also I don't get the point about authData in golang, I can't fine it in here <a href="https://golang.org/pkg/crypto/cipher/#NewGCM" rel="nofollow noreferrer">https://golang.org/pkg/crypto/cipher/#NewGCM</a></p>