Encrypting / Decrypting Request

Ed25519 Example:

Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error. Below is a TypeScript code snippet that demonstrates how to sign a plaintext message with Ed25519. This signature is later verified by the ENSC API server to ensure data integrity.

import * as crypto from 'crypto';

/**
 * Signs a plaintext message using Ed25519.
 *
 * @param message - The plaintext message to sign.
 * @param privateKey - The PEM-formatted private key.
 * @returns The signature as a base64-encoded string.
 */
function signMessage(message: string, privateKey: string): string {
  const signature = crypto.sign(null, Buffer.from(message, 'utf8'), {
    key: privateKey,
    format: 'pem',
  });
  return signature.toString('base64');
}

// Example usage:
const message = 'Hello ENSC!';
const privateKey = `-----BEGIN PRIVATE KEY-----
YOUR_PRIVATE_KEY_CONTENT
-----END PRIVATE KEY-----`;

const signature = signMessage(message, privateKey);
console.log('Signature (base64):', signature);

AES Example:

This example shows how to encrypt and decrypt a payload using AES-256-GCM. The ENSC API client encrypts the JSON payload before sending it, and the server decrypts it using the shared encryption key.

Last updated