Unable to Decrypt AWS KMS encrypted code using Golang, Error: InvalidCiphertextException

54 views Asked by At

I'm trying to decrypt the AWS KMS encrypted code but getting error of InvalidCiphertextException:

operation error KMS: Decrypt, https response error StatusCode: 400, RequestID: 9e69224b-7c29-4e89-9d75-a7aa3b5f077a, InvalidCiphertextException:

Below is my code snippet:

ciphertextBlob, err := base64.StdEncoding.DecodeString(event.Request.Code)
        if err != nil {
            fmt.Println("Error decoding ciphertext:", err)
        }
        log.Println("ciphertextBlob--> ", ciphertextBlob)

        input := &kms.DecryptInput{
            CiphertextBlob: ciphertextBlob,
            KeyId:          aws.String(KMS_KEY_ID),
            DryRun:         aws.Bool(true),
        }

        cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(REGION_NAME))
        if err != nil {
            log.Fatalf("unable to load SDK config, %v", err)
        }

        svc := kms.NewFromConfig(cfg)
        result, err := svc.Decrypt(ctx, input)

                pretty.Println("result--> ", result)
        log.Println("err--> ", err)

Where event.Request.Code is like:

"AYADeOIZyUqkW5s7WXfThDn8/hgAggACABVhd3MtY3J5cHRvLXB1YmxpYy1rZXkAREEwZ2x4ZCsyODJmK1lxSXV5MEpnTTRyWDJTd0poeWM5WVM0ZzhmWmphczNTem5TT0xkQzV1S1J2bkFPSnlzc1FKZz09AAt1c2VycG9vbC1pZAAUZXUtc291dGgtMV9n="

And this event is coming from Cognito UserPool

Gettin error as below:

result-->  (*kms.DecryptOutput)(nil)
err-->  operation error KMS: Decrypt, https response error StatusCode: 400, RequestID: 9e69224b-7c29-4e89-9d75-a7aa3b5f077a, InvalidCiphertextException: 
0

There are 0 answers