EpochLock

Encryption & Decryption Examples

These examples demonstrate how to generate a key, encrypt data, and decrypt data using the EpochLock API in various languages. Ensure you replace placeholders with your actual headers and API values.

Python
import requests
import time
import hashlib

url = "https://api.epochlock.com/encrypt"
timestamp = str(int(time.time() * 1000))
api_key = hashlib.sha256((timestamp + "SuperSecureAPIKey").encode()).hexdigest()
headers = {
    "X-TIMESTAMP": timestamp,
    "X-API-KEY": api_key,
    "X-EMAIL": "you@example.com"
}
data = {
    "data": "Encrypt this text!",
    "include_decryption_info": True
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
Node.js
const axios = require('axios');
const crypto = require('crypto');

const timestamp = Date.now().toString();
const secret = "SuperSecureAPIKey";
const apiKey = crypto.createHash('sha256').update(timestamp + secret).digest('hex');

const headers = {
  'X-TIMESTAMP': timestamp,
  'X-API-KEY': apiKey,
  'X-EMAIL': 'you@example.com'
};

const data = {
  data: "Encrypt this text!",
  include_decryption_info: true
};

axios.post('https://api.epochlock.com/encrypt', data, { headers })
  .then(res => console.log(res.data))
  .catch(err => console.error(err));
cURL
curl -X POST https://api.epochlock.com/encrypt \
  -H "X-TIMESTAMP: 1713904356241" \
  -H "X-API-KEY: your_generated_api_key" \
  -H "X-EMAIL: you@example.com" \
  -H "Content-Type: application/json" \
  -d '{"data": "Encrypt this text!", "include_decryption_info": true}'
PHP
$timestamp = round(microtime(true) * 1000);
$apiKey = hash('sha256', $timestamp . 'SuperSecureAPIKey');

$headers = [
    "X-TIMESTAMP: $timestamp",
    "X-API-KEY: $apiKey",
    "X-EMAIL: you@example.com",
    "Content-Type: application/json"
];

$body = json_encode([
    "data" => "Encrypt this text!",
    "include_decryption_info" => true
]);

$ch = curl_init('https://api.epochlock.com/encrypt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;

public class EncryptExample {
  public static void main(String[] args) throws Exception {
    long timestamp = System.currentTimeMillis();
    String secret = "SuperSecureAPIKey";
    String apiKey = bytesToHex(MessageDigest.getInstance("SHA-256")
            .digest((timestamp + secret).getBytes(StandardCharsets.UTF_8)));

    Map data = new HashMap<>();
    data.put("data", "Encrypt this text!");
    data.put("include_decryption_info", true);

    Gson gson = new Gson();
    String requestBody = gson.toJson(data);

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.epochlock.com/encrypt"))
        .header("Content-Type", "application/json")
        .header("X-TIMESTAMP", String.valueOf(timestamp))
        .header("X-API-KEY", apiKey)
        .header("X-EMAIL", "you@example.com")
        .POST(HttpRequest.BodyPublishers.ofString(requestBody))
        .build();

    HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
    System.out.println(response.body());
  }

  private static String bytesToHex(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) sb.append(String.format("%02x", b));
    return sb.toString();
  }
}
C#
using System;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
        var secret = "SuperSecureAPIKey";
        var rawKey = timestamp + secret;
        var sha256 = SHA256.Create();
        var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(rawKey));
        var apiKey = BitConverter.ToString(hash).Replace("-", "").ToLower();

        var client = new HttpClient();
        var content = new StringContent("{\"data\":\"Encrypt this text!\",\"include_decryption_info\":true}", Encoding.UTF8, "application/json");
        client.DefaultRequestHeaders.Add("X-TIMESTAMP", timestamp);
        client.DefaultRequestHeaders.Add("X-API-KEY", apiKey);
        client.DefaultRequestHeaders.Add("X-EMAIL", "you@example.com");

        var response = await client.PostAsync("https://api.epochlock.com/encrypt", content);
        var responseBody = await response.Content.ReadAsStringAsync();
        Console.WriteLine(responseBody);
    }
}

If your preferred language isn’t listed or you need help integrating EpochLock, feel free to contact support@epochlock.com.