Skip to content

Instantly share code, notes, and snippets.

Created Mar 12, 2019
What would you like to do?
import json
import uuid
import time
import hashlib
import base64
from ecdsa import SigningKey
from ecdsa.util import sigencode_der
bundle_id = 'com.myapp'
key_id = 'XWSXTGQVX2'
product = 'com.myapp.product.a'
offer = 'REFERENCE_CODE' # This is the code set in ASC
application_username = 'user_name' # Should be the same you use when
# making purchases
nonce = uuid.uuid4()
timestamp = int(round(time.time() * 1000))
payload = '\u2063'.join([bundle_id,
str(nonce), # Should be lower case
# Read the key file
with open('cert.der', 'rb') as myfile:
der =
signing_key = SigningKey.from_der(der)
signature = signing_key.sign(payload.encode('utf-8'),
encoded_signature = base64.b64encode(signature)
print(str(encoded_signature, 'utf-8'), str(nonce), str(timestamp), key_id)
Copy link

arifulalam commented Apr 12, 2019

Hi :),
Is this possible to generate this signature using PHP instead of Python?


Copy link

alexcc4 commented May 24, 2019

Hi, I just try, not working.It seems invalid signature.Any update?

Copy link

xiongjinpeng commented Feb 23, 2022

payload.encode('utf-8') maybe modify to payload.decode("unicode_escape").encode('utf-8') ?

Copy link

pnico commented May 10, 2022

payload.encode('utf-8') maybe modify to payload.decode("unicode_escape").encode('utf-8') ?

@xiongjinpeng I owe you a beer ❤️ why is this needed? I don't care, it works now 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment