-
-
Save jeiting/e47139e687bb62688eaf5efe34d9fe71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
key_id, | |
product, | |
offer, | |
application_username, | |
str(nonce), # Should be lower case | |
str(timestamp)]) | |
# Read the key file | |
with open('cert.der', 'rb') as myfile: | |
der = myfile.read() | |
signing_key = SigningKey.from_der(der) | |
signature = signing_key.sign(payload.encode('utf-8'), | |
hashfunc=hashlib.sha256, | |
sigencode=sigencode_der) | |
encoded_signature = base64.b64encode(signature) | |
print(str(encoded_signature, 'utf-8'), str(nonce), str(timestamp), key_id) |
Hi, I just try, not working.It seems invalid signature.Any update?
payload.encode('utf-8') maybe modify to payload.decode("unicode_escape").encode('utf-8') ?
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
Hi :),
Is this possible to generate this signature using PHP instead of Python?
Regards