Generating the signature ✅
Coming Soon!
This is the last part of the tutorial !!! You have made it through !
Here are some code snippets that shows you how to generate the signature in different languages:
Python / Django / Flask
Javascript / Node
Ruby / Rails
1
import hmac
2
import hashlib
3
4
stripe_customer_id = "cus_12345678"
5
uicheck_id="your_uicheck_id"
6
uicheck_secret="your_uicheck_secret"
7
8
signature = hmac.new(
9
uicheck_secret.encode("ascii"), # keep this secret safe on your server.
10
(uicheck_id + stripe_customer_id).encode("ascii"),
11
digestmod=hashlib.sha256, # hash function
12
).hexdigest() # pass this result to the frontend.
13
14
print(signature) # prints something like 22af9d...c00d8c
15
Copied!
1
const crypto = require("crypto");
2
3
var stripe_customer_id = "cus_12345678"
4
var uicheck_id="your_uicheck_id"
5
var uicheck_secret="your_uicheck_secret"
6
7
const signature = crypto.createHmac(
8
"sha256",
9
uicheck_secret // keep this secret safe on your server.
10
).update(uicheck_id + stripe_customer_id).digest("hex") // pass the result to the frontend.
11
12
console.log(signature) // prints something like 22af9d...c00d8c
Copied!
1
require 'openssl'
2
3
stripe_customer_id = "cus_12345678"
4
uicheck_id="your_uicheck_id"
5
uicheck_secret="your_uicheck_secret"
6
7
signature = OpenSSL::HMAC.hexdigest(
8
'sha256', # hash function
9
uicheck_secret, # keep this secret safe on your server.
10
(uicheck_id + uicheck_secret) # pass this result to the frontend.
11
) # pass the result to the frontend.
12
13
puts(signature) # prints something like 22af9d...c00d8c
Copied!

How to use the signature generation snippets

Here is a secure way to generate the above snippets in your backend code.
Put your uicheck_id and uicheck_secret in environment variables on your backend server so they are safely stored.
Then you can encapsulate the signature generator into a service. Here is an example in python:
1
import hmac
2
import hashlib
3
import os
4
5
class UicheckService:
6
def get_uicheck_signature(self, stripe_customer_id):
7
uicheck_id = os.environ['UICHECK_ID']
8
uicheck_secret = os.environ['UICHECK_SECRET']
9
10
signature = hmac.new(
11
uicheck_secret.encode("ascii"), # keep this secret safe on your server.
12
(uicheck_id + stripe_customer_id).encode("ascii"),
13
digestmod=hashlib.sha256, # hash function
14
).hexdigest() # pass this result to the frontend.
15
16
return signature
Copied!
And then you could use the service like this
1
from services import UicheckService
2
3
stripe_customer_id = # here get the stripe_customer_id from your database
4
uicheck_signature = UicheckService().get_uicheck_signature(stripe_customer_id)
5
uicheck_id = os.environ['UICHECK_ID']
6
7
# return to the frontend stripe_customer_id, uicheck_signature and uicheck_id
Copied!

Troubleshooting signature

UiCheck provides you with a tool to easily debug the code that generates the signature. You can see the expected signature in the preview section of the home page.
You can compare this signature to what your code generates. They should be identical.
Need more help? Chat with us on Facebook! We will be happy to see how we can help you and improve our doc. If something is not clear we would love to hear about it 😍