You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/67_hmac_function.sql
+20-21Lines changed: 20 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -27,9 +27,13 @@ Think of it like a wax seal on a letter - only someone with the right seal (your
27
27
The `sqlpage.hmac` function takes three inputs:
28
28
1. **Your data** - The text you want to sign (like a message or request body)
29
29
2. **Your secret key** - A password only you know (keep this safe!)
30
-
3. **Algorithm** (optional) - Either `sha256` (default) or `sha512`
30
+
3. **Algorithm** (optional) - The hash algorithm and output format:
31
+
- `sha256` (default) - SHA-256 with hexadecimal output
32
+
- `sha256-base64` - SHA-256 with base64 output
33
+
- `sha512` - SHA-512 with hexadecimal output
34
+
- `sha512-base64` - SHA-512 with base64 output
31
35
32
-
It returns a long string of letters and numbers (the signature). If someone changes even one letter in your data, the signature will be completely different.
36
+
It returns a signature string. If someone changes even one letter in your data, the signature will be completely different.
33
37
34
38
### Example 1: Verify Shopify Webhooks
35
39
@@ -39,27 +43,21 @@ When Shopify sends you a webhook (like when someone places an order), it include
39
43
-- Shopify includes the signature in the X-Shopify-Hmac-SHA256 header
WHEN sqlpage.hmac('The quick brown fox jumps over the lazy dog', 'key', 'sha256') ='f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8'
4
-
THEN 'It works ! HMAC SHA-256 hash is correct'
5
-
ELSE 'Hash mismatch: '||sqlpage.hmac('The quick brown fox jumps over the lazy dog', 'key', 'sha256')
6
-
END as contents;
1
+
-- Redirect if hash doesn't match expected value
2
+
SELECT'redirect'as component, '/error.sql'as link
3
+
WHEREsqlpage.hmac('The quick brown fox jumps over the lazy dog', 'key', 'sha256') !='f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8';
4
+
5
+
SELECT'text'as component, 'It works ! HMAC SHA-256 hash is correct'as contents;
WHEN sqlpage.hmac('The quick brown fox jumps over the lazy dog', 'key', 'sha512') ='b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a'
4
-
THEN 'It works ! HMAC SHA-512 hash is correct'
5
-
ELSE 'Hash mismatch: '||sqlpage.hmac('The quick brown fox jumps over the lazy dog', 'key', 'sha512')
6
-
END as contents;
1
+
-- Redirect if hash doesn't match expected value
2
+
SELECT'redirect'as component, '/error.sql'as link
3
+
WHEREsqlpage.hmac('The quick brown fox jumps over the lazy dog', 'key', 'sha512') !='b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a';
4
+
5
+
SELECT'text'as component, 'It works ! HMAC SHA-512 hash is correct'as contents;
0 commit comments