Webhook Relay
PricingLogin
  • Introduction
  • Quick Start - Forwarding
  • Quick Start - Tunnels
  • 🛠️Installation
    • Relay CLI
      • Install
      • Auto-start
      • Run config.yaml reference
    • Containerized
      • Kubernetes Installation
      • Podman
      • Docker
      • Docker Compose
  • Products
    • 🛰️Webhook Forwarding
      • Glossary
      • WebSocket Server
      • Authentication
      • Custom Domains
    • ⚡Functions
      • Managing functions
      • Edit request/response
      • Working with JSON
      • 🦾Advanced
        • Working with time
        • Testing functions in CLI
        • Making HTTP Requests
        • Multipart Form Data
        • URLEncoded Form Data
        • GCP BigQuery
        • Sending Emails
        • JWT authentication
        • Base64, Hashes, Encryption
      • 🤖Integrating into CI/CD
    • 🔃Tunnels
      • Using tunnels
      • Custom Domains
      • Encryption (HTTPS)
      • Regions
  • 📝Examples
    • Intro to examples
    • Webhooks
      • Receiving webhooks on localhost
      • Receive webhooks inside your JavaScript app
      • Execute shell scripts on remote machines
    • Functions
      • Enrich webhooks from 3rd party APIs
      • Convert DockerHub webhook to Slack notification
      • Allowing only POST requests through
      • Manipulate webhook request body
    • Tunnels
      • Ingress for any Kubernetes environment
      • Demoing your website
    • 🏠Home Automation
      • Home Assistant
      • Node-RED
      • Raspberry Pi
  • Platform
    • CLI Basics
    • Using CLI Behind Proxy
    • Self-hosting Server
      • Server deployment
      • Client configuration
    • Security & Tech
Powered by GitBook
On this page
  • Encoding and decoding base64 data
  • Create MD5 hash
  • Create SHA1, SHA256, SHA512 hashes
  • Calculating HMAC
  • Calculating CRC32 checksum

Was this helpful?

  1. Products
  2. Functions
  3. Advanced

Base64, Hashes, Encryption

Webhook Relay provides a helper package to deal with various hashing and cryptography related operations.

Encoding and decoding base64 data

When base64 encoding is needed, import crypto package:

-- importing the package
local crypto = require('crypto')

local encoded = crypto.base64_encode("some value")

-- do something with encoded value

To decode some value:

-- importing the package
local crypto = require('crypto')

-- supplying base64 value
local decoded, err = crypto.base64_decode("aGVsbG8gd29ybGQ=")
if err then error(err) end

-- do something with 'decoded' value

Create MD5 hash

-- importing the package
local crypto = require('crypto')

local md5_hashed_value = crypto.md5("<some value to hash>")

Note: MD5 is considered cryptographically broken, if you can, use SHA256 hashing algorithm.

Create SHA1, SHA256, SHA512 hashes

-- importing the package
local crypto = require('crypto')

-- to hash with SHA1
local sha1_hashed_value = crypto.sha1("<some value to hash>")

-- to hash with SHA256
local sha256_hashed_value = crypto.sha256("<some value to hash>")

-- to hash with SHA512
local sha512_hashed_value = crypto.sha512("<some value to hash>")

Calculating HMAC

-- importing the package
local crypto = require('crypto')

-- to calculate HMAC of the request body using SHA256:
local calculated_hmac = crypto.hmac('sha256', r:RequestBody , '<secret key>')

-- check whether calculated HMAC matches the one that was sent
-- with the message

Method hmac takes three parameters:

  1. Algorithm, valid values: md5, sha1, sha256, sha512

  2. Data to verify

  3. Secret key in a string form (not base64 encoded)

Calculating CRC32 checksum

-- importing the package
local crypto = require('crypto')

-- to get a string value of crc hash (uses hex encoding):
local encoded_crc2 = crypto.crc32(r:RequestBody)

-- to get a raw value:
local raw_crc2 = crypto.crc32(r:RequestBody, true)
PreviousJWT authenticationNextIntegrating into CI/CD

Last updated 3 years ago

Was this helpful?

To create based hashes:

hashing functions are provided by the crypto package:

can be calculated using MD5, SHA1, SHA256 and SHA512 algorithms combined with the data and the key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.

is an error-detecting code commonly used to detect accidental changes to raw data. It computes the CRC-32 checksum using the IEEE polynomial.

⚡
🦾
MD5 message-digest algorithm
SHA-2 (Secure Hash Algorithm 2)
HMAC
CRC32