# LTI Pro API X-Lti-Signature Generation in Python

**URL:** <https://devforum.zoom.us/t/lti-pro-api-x-lti-signature-generation-in-python/86705>\
**Category:** API and Webhooks\
**Created:** [April 14, 2023, 5:16pm UTC](https://devforum.zoom.us/t/lti-pro-api-x-lti-signature-generation-in-python/86705 "2023-04-14T17:16:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![K7CTC](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@K7CTC](https://devforum.zoom.us/u/K7CTC)\
**Post date:** [April 14, 2023, 5:16pm UTC](https://devforum.zoom.us/t/lti-pro-api-x-lti-signature-generation-in-python/86705/1 "2023-04-14T17:16:04Z")

</div>

Just wanted to share the solution I came up with for generating the X-Lti-Signature using Python:

```auto
import base64
import time
import hmac
from hashlib import sha1

LTI_KEY = 'from LTI Pro configuration page in marketplace'
LTI_SECRET = 'from LTI Pro configuration page in marketplace'

#get current unix timestamp in milliseconds
timestamp = str(int(time.time())) + '000'

#create base string using query parameters (LTI key & timestamp in milliseconds)
base_string = f'key={LTI_KEY}&timestamp={timestamp}'

#create HMAC object by passing base string and LTI secret to the HMAC-SHA1 hashing algorithm
hmac_object = hmac.new(LTI_SECRET.encode('utf-8'), base_string.encode('utf-8'), sha1)

#get HMAC digest (returns bytes object)
hmac_object_digest = hmac_object.digest()

#signature equals converted HMAC digest to base64 URL safe string with trailing equal sign removed
signature = (base64.urlsafe_b64encode(hmac_object_digest)).decode('utf-8').rstrip('=')

#here's your X-Lti-Signature, valid for 60 minutes
print('Signature: ' + signature)

```

Hope this helps someone out!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [April 17, 2024, 8:52am UTC](https://devforum.zoom.us/t/lti-pro-api-x-lti-signature-generation-in-python/86705/2 "2024-04-17T08:52:51Z")

</div>

Closed on April 17, 2024, 8:52am UTC

This topic was automatically closed 368 days after the last reply. New replies are no longer allowed.
