Skip to content

Instantly share code, notes, and snippets.

@ezekg
ezekg / _README.md
Last active August 19, 2023 10:30
How to verify a signed license key using C#, Ed25519 and the NSEC crypto package. See: https://keygen.sh

Setup dependencies

dotnet --version
# => 6.0.101

dotnet add package NSec.Cryptography

Run the example

@ezekg
ezekg / ANSI.md
Created August 12, 2021 20:47 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1b
  • Decimal: 27
@ezekg
ezekg / updateProxy.ts
Created August 6, 2021 13:57 — forked from sploders101/updateProxy.ts
Example update proxy for electron
import http from "http";
import https from "https";
import {
AddressInfo,
} from "net";
import { URL } from "url";
const updateServer = "https://updates.yourserver.com/path/to/update/dir/without/trailing/slash";
const updateAuth = `Basic ${Buffer.from("username:password").toString("base64")}`
@ezekg
ezekg / keygen-cryptographic-key-verification.cs
Created June 30, 2021 11:59
Using BouncyCastle to verify license keys cryptographically signed using RSA PKCS1 v1.5.
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Security;
using System.Text;
using System;
class Program
{
const string KEYGEN_LICENSE_KEY = "key/eyJhY2NvdW50Ijp7ImlkIjoiMWZkZGNlYzgtOGRkMy00ZDhkLTliMTYtMjE1Y2FjMGY5YjUyIn0sInByb2R1Y3QiOnsiaWQiOiI3MDcxZmVmZi1iNWYzLTQzNGEtODNjMS0zYWIzZjM1OTIzMjUifSwicG9saWN5Ijp7ImlkIjoiOWE0MDI1MTItOGUzZC00YWMxLTkyYjktZTIxMzE3ZDY3MjNjIiwiZHVyYXRpb24iOm51bGx9LCJ1c2VyIjpudWxsLCJsaWNlbnNlIjp7ImlkIjoiYThjODUxMzUtYWM3MS00Y2ZiLWFmZGQtMzEyZTNmNjg5MDM3IiwiY3JlYXRlZCI6IjIwMjEtMDYtMzBUMTE6NTQ6NDAuMTU5WiIsImV4cGlyeSI6bnVsbH19.egtTIhlFr9PfC8mr47wjzac7XbliK9218JM0APCQSonwfUxYWmN_aVILCbzlmxrrp2LtNmuclHEE_Hz6dihrxua1gYl5WtkhVVpsiE58m1ypsbczDnA1QIj-3uhicQt05mnv2MO7zRL335vcCrse_OFwy8QwZtSswsBYnNa_VE0RVjtrwAf4mrWjB5ASqFc9d-44u2c7R0VVB8ODF0A7telSa9ZbHOkl8gborW45SQT0GLqCK3a1NvHmX_nJ9PR3N8RfHsa3cblmOlsOA-7VCyoJulNdbpwo1xItO28oCOvoqV2P9XDhqfKBEMgyUhgdm_yml3ezJPjfL8l6S-shxw==";
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.backends import default_backend
from cryptography.exceptions import InvalidSignature
import base64
import sys
import os
# Cryptographically verify the activation proof using our public key
def verify_activation_proof(activation_proof):
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Security;
using System.Text;
using System;
class Program
{
const string KEYGEN_ACTIVATION_PROOF = "proof/eyJhY2NvdW50Ijp7ImlkIjoiYjEyMmRmN2MtN2UzNi00NjNiLTlhYzMtYzkzZmYzOGIzMTFmIn0sInByb2R1Y3QiOnsiaWQiOiJiZWZlMjBjMS05MTE4LTQ2MmMtYWFhNS0yMWE2MmUxNmU5NWEifSwicG9saWN5Ijp7ImlkIjoiYTg2YWU0NmUtMTQzMS00ZDVjLWJkNzUtN2YzODNlZDY4YjA2IiwiZHVyYXRpb24iOjg2NDAwfSwibGljZW5zZSI6eyJpZCI6IjI2MzhiZWFmLTIwMWMtNDg5ZS1iODA2LTRhOWEwN2ZhYzA4OSIsImtleSI6ImtleS9ORlJMUmkwMFYxWlNMVlZHTkZndE4xZElTQzFOVkZsTUxWWktXRTR0TjAwelJpMVFVbGRTLm5UMXBENFA2OUFnVTNVa0x3eFlLU19RNU03RHV3ekZtZ0pDOWd2N1ZGUmNiWkxJYUZsSVktY2hMbnEtUTNNUVk1dlUydURobHNXUkhfQnBHRkVITDZxcFIzQ1otX2lVYmdoU2pBM1FiNl80RVVhcjBTMlhsd2d2ZHUyVFJHTGRkRG52cTBaOGEtak1vRmpnc1RVVzZqZG5yR1NBQUNFQkNHX0I0QkVQWTN2MEVBeE5GUTJRU1RwUE1jbFhhTGlKWlZIa0NSSGhQdWI5T0NmN0JTWTVUWWhFLVoxeGVrQ29teXppQlFlWEpVMjJ6MnJqZHVhMEk4WUNvdWJkbkNoUDNtdjI3SWxsQUREaHZpYW1oSHAxNnB5
@ezekg
ezekg / ed25519.js
Last active June 29, 2021 19:27
Encoding a hexidecimal Ed25519 verify key to DER format using Node.
const crypto = require('crypto')
{
const verifyKey = 'e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788'
const licenseKey = 'key/Njg1ZjkwMDY5OGZkOWNiZTYwODRlNmRhZDdmMGU3NjI=.V0MIuqrUfTnPrCAPqi8YfnpGHNluoGs1QG0XqZ67D8q9dQvtuEaKVz_7w5cZkcYvOkNbvE28w8P4xVemXbBqAA=='
// Encode hexidecimal key into DER format (Node doesn't accept hex format)
const oid = Buffer.from([0x06, 0x03, 0x2B, 0x65, 0x70])
const key = Buffer.from(verifyKey, 'hex')
const elements = Buffer.concat([
Serializer outputs ----------------------------------
alba {"id":1,"body":"post","commenter_names":["John","Jane"],"comments":[{"id":1,"body":"Comment1"},{"id":2,"body":"Comment2"}]}
alba_inline {"id":1,"body":"post","commenter_names":["John","Jane"],"comments":[{"id":1,"body":"Comment1"},{"id":2,"body":"Comment2"}]}
ams {"id":1,"body":"post","commenter_names":["John","Jane"],"comments":[{"id":1,"body":"Comment1"},{"id":2,"body":"Comment2"}]}
blueprinter {"body":"post","commenter_names":["John","Jane"],"comments":[{"body":"Comment1","id":1},{"body":"Comment2","id":2}],"id":1}
jbuilder {"id":1,"body":"post","commenter_names":["John","Jane"],"comments":[{"id":1,"body":"Comment1"},{"id":2,"body":"Comment2"}]}
jsonapi {"data":{"id":"1","type":"json_api_standard_post","attributes":{"id":1,"body":"post","commenter_names":["John","Jane"],"comments":[{"id":1,"body":"Comment1"},{"id":2,"body"
@ezekg
ezekg / electron-publisher-custom.js
Last active April 23, 2021 21:10
Custom electron-builder publisher for https://keygen.sh distribution service
/**
* NOTE(ezekg) Place this file in `resources/electron-publisher-custom.js`
*/
const { Publisher } = require('electron-publish')
const { log } = require('builder-util')
const { basename } = require('path')
const { stat } = require('fs-extra')
const { URL } = require('url')
const https = require('https')
const mime = require('mime')
@ezekg
ezekg / functions.php
Last active April 19, 2021 21:06
WooCommerce hook to generate a Keygen license key after a payment is completed
<?php
// Add these variables before running this code
$KEYGEN_PRODUCT_TOKEN = '...'
$KEYGEN_ACCOUNT_ID = '...'
$KEYGEN_POLICY_ID = '...'
// Add a hook after payment is completed
add_action('woocommerce_payment_complete', 'generate_license_key_after_payment_complete');