Skip to content

Xero signature failed on verification. #1

Open
@taitran6879

Description

@taitran6879

Hello, my name is Tai.

Based on the sample here I create an receiver for webhooks, using ngrok and dot net core 2.
After encode the payload with webhook key, i got the following generated signature:
BjzNbYUfrzg4g8wxm+dKHaZVrKxr2m75E296fUbD1E4=

But in the request of webhook, i have this signature as:
/jzNbYUfrzg4g8wxm+dKHaZVrKxr2m75E296fUbD1E4=

Here's the full payload body:
`POST /webhooks HTTP/1.1
Host: 3099768b.ngrok.io
Accept: /
Accept-Encoding: gzip,deflate
Content-Type: application/json; charset=utf-8
x-xero-signature: /jzNbYUfrzg4g8wxm+dKHaZVrKxr2m75E296fUbD1E4=
Content-Length: 95
X-Forwarded-Proto: https
X-Forwarded-For: 34.233.225.118

{"events":[],"firstEventSequence": 0,"lastEventSequence": 0, "entropy": "LUWDSUDGSWNZVALZXBEV"}`

Here's the code for generating signature with given webhooks key:

public bool VerifySignature(string payload, string signatureHeader)
        {
            var generatedSignature = GenerateSignature(
                "LR+QgKlbRciIPYpi65tTKLaZ3FzLLofCNEQWrRXqWXJeDFrfexzfVI9SmnVuCWDJ4jnjHB9ECtOyxZSofRxwWw==",
                payload);

            return generatedSignature == signatureHeader;
        }

        public string GenerateSignature(string signingKey, string dataToHash)
        {
            using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(signingKey)))
            {
                var messageBytes = Encoding.UTF8.GetBytes(dataToHash);
                var hash = hmac.ComputeHash(messageBytes);
                return Convert.ToBase64String(hash);
            }
        }

Please help me to check whether i'm doing wrong or something, why the generated signature and the x-xero-signature only different in 1 character ? It works fine for me last week : (. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions