Skip to main content
This guide explains how to securely decrypt signed and encrypted messages received through a webhook using the CryptUtility class.

Overview

When working with sensitive data in webhooks, it’s important to verify the authenticity and decrypt the content properly. This process involves:
  1. Receiving an encrypted payload
  2. Loading your private key for decryption
  3. Loading the sender’s public key for verification
  4. Verifying and decrypting the message
  5. Processing the decrypted data

Prerequisites

  1. Your private key (for decryption)
  2. Sender public key (for verification)

Implementation Example

The CryptUtility Class Implementation

Below is the implementation of the CryptUtility class that handles the cryptographic operations:
CryptUtility.py

Simple Decryption Function

Here’s a straightforward example function for decrypting and verifying webhook messages:
DescryptionFunction.py

Usage Example

Here’s how you might use this function in a webhook handler:
ExampleUsage.py

Understanding the Message Format

The webhook payload is expected to contain a message with two main components:
  1. encrypted_message: The actual message content, encrypted using a hybrid encryption approach:
    • A symmetric key is generated and used to encrypt the message
    • The symmetric key is encrypted with the recipient’s public key
    • Both are packaged together in a structured format
  2. signature: A cryptographic signature created by the sender to verify authenticity:
    • The signature is created by signing the decrypted message with the sender’s private key
    • The recipient verifies this signature using the sender’s public key

Decrypted Message Structure

After successfully decrypting and verifying the webhook message, the decrypted content will contain data similar to what is returned by the Get Script endpoint response. For detailed information about the expected data structure, refer to: Script Response Data Payload
example_decrypted_data.json