Skip to content

Instantly share code, notes, and snippets.

@ezekg
ezekg / Main.java
Last active Mar 31, 2022
How to verify a signed license key using Java, Ed25519 and the org.bouncycastle/bcprov-jdk15on-1.70 package. See: https://keygen.sh
View Main.java
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
import org.bouncycastle.crypto.signers.Ed25519Signer;
import org.bouncycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.Base64;
class Main {
public static void main(String args[]) {
String licenseKey = "key/eyJhY2NvdW50Ijp7ImlkIjoiMWZkZGNlYzgtOGRkMy00ZDhkLTliMTYtMjE1Y2FjMGY5YjUyIn0sInByb2R1Y3QiOnsiaWQiOiIxZjA4NmVjOS1hOTQzLTQ2ZWEtOWRhNC1lNjJjMjE4MGMyZjQifSwicG9saWN5Ijp7ImlkIjoiMjlkOWQ4ZDMtYmYxZC00NGQxLWExYjktODIwNDQwZDQyMmZmIiwiZHVyYXRpb24iOm51bGx9LCJ1c2VyIjpudWxsLCJsaWNlbnNlIjp7ImlkIjoiZjNkNjU3ZGUtMmI1MC00YWRmLTg2N2ItZWYwM2RjODZhM2ZlIiwiY3JlYXRlZCI6IjIwMjEtMTAtMTRUMTU6MjA6MzIuNjcwWiIsImV4cGlyeSI6IjIwMjEtMTAtMTVUMDA6MDA6MDAuMDAwWiJ9fQ==.Z_fDBaVqmBxHWkzi_TCPWGOrE0rItN_xEFdc8TtR0ahB-Gx84S6r4pXPuTxeIREtLCVJt3lcFy_WuCNeCOFRAA==";
String publicKey = "e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788";
@ezekg
ezekg / license_key_validation.py
Created Feb 7, 2022
An example of validing a license key using Python 3's standard library
View license_key_validation.py
from urllib.request import Request, urlopen
import json
import sys
req = Request(
'https://api.keygen.sh/v1/accounts/demo/licenses/actions/validate-key',
method='POST',
data=json.dumps({
'meta': {
'key': 'C1B6DE-39A6E3-DE1529-8559A0-4AF593-V3',
@ezekg
ezekg / _README.md
Last active Jan 27, 2022
How to verify a signed license key using C#, .NET 6, RSA PKCS1 v1.5 and System.Security.Cryptography. See: https://keygen.sh
View _README.md

Setup dependencies

dotnet --version
# => 6.0.101

Run the example

@ezekg
ezekg / _README.md
Last active Dec 24, 2021
How to verify a signed license key using C#, Ed25519 and the NSEC crypto package. See: https://keygen.sh
View _README.md

Setup dependencies

dotnet --version
# => 6.0.101

dotnet add package NSec.Cryptography

Run the example

@ezekg
ezekg / ANSI.md
Created Aug 12, 2021 — forked from fnky/ANSI.md
ANSI Escape Codes
View ANSI.md

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 Aug 6, 2021 — forked from sploders101/updateProxy.ts
Example update proxy for electron
View updateProxy.ts
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 Jun 30, 2021
Using BouncyCastle to verify license keys cryptographically signed using RSA PKCS1 v1.5.
View keygen-cryptographic-key-verification.cs
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==";
View keygen-cryptographic-proof-verification.py
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):
View keygen-cryptographic-proof-verification.cs
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 Jun 29, 2021
Encoding a hexidecimal Ed25519 verify key to DER format using Node.
View ed25519.js
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([