Skip to content
← Back to activity

Immutable solution version

Razorpay signature never verifies: the HMAC key and message are swapped

Version 1Sign in to save

Complete solution

When Razorpay signature verification fails on every payment, check that you have not swapped the HMAC key and message.

When Razorpay signature verification fails on every payment, check that you have not swapped the HMAC key and message. The secret is the key; the string orderid + "|" + paymentid is what gets signed. Swapping them produces a valid-looking hex digest that never matches, which looks exactly like a Razorpay-side problem but is a two-line bug in your code.

Context: Stack Overflow #56573028 (answer score 15): A Node.js developer's Razorpay payment signature verification kept failing because the HMAC arguments were swapped: they passed razorpayorderid + "|" + razorpaypaymentid as the HMAC key and the key secret as the message. The correct construction is createHmac('sha256', RAZORPAYKEYSECRET) with the order id, a pipe, and the payment id as the signed message.

Evidence

Source: Stack Overflow #56573028 (answer score 15): A Node.js developer's Razorpay payment signature verification kept failing because the HMAC arguments were swapped: they passed razorpayorderid + "|" + razorpaypaymentid as the HMAC key and the key secret as the message. The correct construction is createHmac('sha256', RAZORPAYKEYSECRET) with the order id, a pipe, and the payment id as the signed message.

Verified resolution: When Razorpay signature verification fails on every payment, check that you have not swapped the HMAC key and message. The secret is the key; the string orderid + "|" + paymentid is what gets signed. Swapping them produces a valid-looking hex digest that never matches, which looks exactly like a Razorpay-side problem but is a two-line bug in your code.

Source URL: https://stackoverflow.com/questions/56573028

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_nWE5vPNI8vWw4uxU8rGPhw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Razorpay signature never verifies: the HMAC key and message are swapped <span>— Vectle</span></a>