{"record":{"id":"cbe53204467e0e28","repo":"getsops/sops","slug":"could-not-create-gcm-s","errorCode":null,"errorMessage":"Could not create GCM: %s","messagePattern":"Could not create GCM: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"aes/cipher.go","lineNumber":161,"sourceCode":"\t\treturn \"\", nil\n\t}\n\taescipher, err := cryptoaes.NewCipher(key)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Could not initialize AES GCM encryption cipher: %s\", err)\n\t}\n\tvar iv []byte\n\tif stash, ok := c.stash[stashKey{plaintext: plaintext, additionalData: additionalData}]; !ok {\n\t\tiv = make([]byte, nonceSize)\n\t\t_, err = rand.Read(iv)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"Could not generate random bytes for IV: %s\", err)\n\t\t}\n\t} else {\n\t\tiv = stash\n\t}\n\tgcm, err := cipher.NewGCMWithNonceSize(aescipher, nonceSize)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Could not create GCM: %s\", err)\n\t}\n\tvar plainBytes []byte\n\tvar encryptedType string\n\tswitch value := plaintext.(type) {\n\tcase string:\n\t\tencryptedType = \"str\"\n\t\tplainBytes = []byte(value)\n\tcase int:\n\t\tencryptedType = \"int\"\n\t\tplainBytes = []byte(strconv.Itoa(value))\n\tcase float64:\n\t\tencryptedType = \"float\"\n\t\t// The Python version encodes floats without padding 0s after the decimal point.\n\t\tplainBytes = []byte(strconv.FormatFloat(value, 'f', -1, 64))\n\tcase bool:\n\t\tencryptedType = \"bool\"\n\t\t// The Python version encodes booleans with Titlecase\n\t\tif value {","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/aes/cipher.go#L143-L179","documentation":"After obtaining the IV, Encrypt constructs a GCM AEAD instance with cipher.NewGCMWithNonceSize using the 32-byte nonce size SOPS uses. If the AEAD cannot be constructed (key/cipher state invalid), this error wraps the stdlib message. Since the AES cipher was already validated, this failure is rare and typically indicates an incompatibility between the cipher object and GCM mode.","triggerScenarios":"Calling Cipher.Encrypt when cipher.NewGCMWithNonceSize(aescipher, 32) fails — essentially only when the aescipher built from the key is invalid or the linked crypto library lacks GCM support (e.g. FIPS builds with GCM disabled).","commonSituations":"Go builds with GCMForbidden/FIPS restrictions; unusual crypto providers substituted via build tags; corrupted binary or mismatched stdlib version.","solutions":["Confirm the Go crypto/aes package supports GCM in your build (no FIPS GCM restriction).","Rebuild the binary against a standard Go toolchain without crypto overrides.","If it persists, log the underlying error and file an issue — this indicates a crypto library problem, not bad input."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"ciphertext, err := cipher.Encrypt(v, key, ad)\nif err != nil && strings.Contains(err.Error(), \"Could not create GCM\") {\n    // crypto environment problem: fail fast, report to platform team\n}","preventionTips":["Use a standard Go toolchain without crypto/FIPS restrictions","Verify GCM availability once at startup with a self-test encryption","Keep the binary and stdlib versions consistent"],"tags":["sops","aes","gcm","encryption","crypto"],"backgroundTag":"aead-init-failed","analyzedSha":"13442bb98183887d7a9ac09ec8ab0564673a59d8","analyzedAt":"2026-09-01T03:53:00.447Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}