Skip to content

Instantly share code, notes, and snippets.

View markscottwright's full-sized avatar

Mark Wright markscottwright

  • Washington, DC
View GitHub Profile
@markscottwright
markscottwright / CertFetcher.java
Created December 12, 2018 17:41
How to fetch certificates from a TLS connection
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@markscottwright
markscottwright / PKCS7.java
Last active June 16, 2024 15:27
How to create a PKCS7/CMS signature using BouncyCastle
package scratch;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.Security;
@markscottwright
markscottwright / DisableHttpSecurity.java
Created March 1, 2019 20:17
How to disable TLS certificate verification in java
package scratch;
import java.io.IOException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
@markscottwright
markscottwright / movemouse.cpp
Last active September 29, 2020 20:53
How to move a mouse cursor to a particular monitor
#include <windows.h>
#include <stdio.h>
#include <string.h>
RECT monitors[100];
int numMonitors = 0;
BOOL SaveMonitorInfo(
HMONITOR Arg1,
HDC Arg2,
@markscottwright
markscottwright / gist:6b55d9b01d5769e9a7924dfaca40b4b5
Last active August 10, 2021 15:12
How to get an Azure Managed Identity token using curl
token=`curl -s 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fstorage.azure.com' -H Metadata:true | grep -o 'access.token[": ]\+[^"]\+' | sed s/access_token...//`
@markscottwright
markscottwright / Totp.java
Created September 23, 2021 16:27
How to do a totp in Java
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base32;
@markscottwright
markscottwright / QrCodeExtractor.java
Created September 23, 2021 19:57
How to extract the totp secret from a QR code
package scratch;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.imageio.ImageIO;
import com.google.zxing.BinaryBitmap;
@markscottwright
markscottwright / .inputrc
Created November 14, 2021 04:14
VI mode inputrc
set editing-mode vi
set bell-style none
$if mode=vi
set keymap vi-command
"gg": beginning-of-history
"G": end-of-history
set keymap vi-insert
"kj": vi-movement-mode
"\C-w": backward-kill-word
"\C-p": history-search-backward
@markscottwright
markscottwright / Main.java
Last active February 9, 2022 00:11
How to use an SSH2 key in Java.
import static org.bouncycastle.crypto.util.OpenSSHPrivateKeyUtil.parsePrivateKeyBlob;
import java.io.IOException;
import java.io.StringReader;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
@markscottwright
markscottwright / ImageOcr.java
Last active May 9, 2022 09:49
A single-file (although depending on Tesseract) tool for extracting text from images.
package scratch;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;