Skip to content

Instantly share code, notes, and snippets.

@ikrahul
Forked from OlivierKobialka/regex.md
Created March 5, 2025 21:46
Show Gist options
  • Select an option

  • Save ikrahul/f04bfe0c49d630cf5327fba80cb31c77 to your computer and use it in GitHub Desktop.

Select an option

Save ikrahul/f04bfe0c49d630cf5327fba80cb31c77 to your computer and use it in GitHub Desktop.
Private and Public Key Regex

Match Private and Public Keys using Regular Expressions

  1. Ethereum (ETH)
  2. Bitcoin (BTC)
  3. Monero (XMR)
  4. PuTTY SSH RSA Key
  5. PuTTY SSH DSA Key
  6. ECDSA Private Key
  7. SSL Certificate
  8. John the Ripper
  9. Password etc passwd
  10. Password etc shadow
  11. JWK
  12. PGP Private
  13. SSH DDS Public
  14. SSH RSA Public
  15. PKCS7 Encrypted Data
  16. PGP Header
  17. PGP Public

Private Keys πŸ”

Ethereum (ETH)

/(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/

Bitcoin (BTC)

/^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/g

Monero (XMR)

/4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}$/g

PuTTY SSH RSA Key

/^PuTTY-User-Key-File-2: ssh-rsa\s*Encryption: none(?:.|\s?)*?Private-MAC:$/

PuTTY SSH DSA Key

/^PuTTY-User-Key-File-2: ssh-dss\s*Encryption: none(?:.|\s?)*?Private-MAC:$/

ECDSA Private Key

/^-----BEGIN ECDSA PRIVATE KEY-----\s.*,ENCRYPTED(?:.|\s)+?-----END ECDSA PRIVATE KEY-----$/

SSL Certificate

/^-----BEGIN CERTIFICATE-----(?:.|\n)+?\s-----END CERTIFICATE-----$/

John the Ripper

/^[J,j]ohn\ [T,t]he\ [R,r]ipper|john-[1-9].[1-9].[1-9]|Many\ salts:|Only\ one\ salt:|openwall.com/john/|List.External:[0-9a-zA-Z]*|Loaded\ [0-9]*\ password hash|guesses:\ \d*\ \ time:\ \d*:\d{2}:\d{2}:\d{2}|john\.pot$/

Password etc passwd

/^[a-zA-Z0-9\-]+:[x|\*]:\d+:\d+:[a-zA-Z0-9/\- "]*:/[a-zA-Z0-9/\-]*:/[a-zA-Z0-9/\-]+$/

Password etc shadow

/^[a-zA-Z0-9\-]+:(?:(?:!!?)|(?:\*LOCK\*?)|\*|(?:\*LCK\*?)|(?:\$.*\$.*\$.*?)?):\d*:\d*:\d*:\d*:\d*:\d*:$/

JWK

/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm

PGP Private

/^(-----BEGIN PGP PRIVATE KEY BLOCK-----).*([a-zA-Z0-9//\n\/\.\:\+\ \=]+).*(-----END PGP PRIVATE KEY BLOCK-----)$/

Public Keys πŸ”‘

Ethereum Public (ETH)

/(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/

SSH DDS Public

/^ssh-dss [0-9A-Za-z+/]+[=]{2}$/

SSH RSA Public

/^ssh-rsa AAAA[0-9A-Za-z+/]+[=]{0,3} [^@]+@[^@]+$/

PKCS7 Encrypted Data

/^(?:Signer|Recipient)Info(?:s)?\ ::=\ \w+|[D|d]igest(?:Encryption)?Algorithm|EncryptedKey\ ::= \w+$/

PGP Header

/^-{5}(?:BEGIN|END)\ PGP\ MESSAGE-{5}$/

PGP Public

/^(-----BEGIN PGP PUBLIC KEY BLOCK-----).*([a-zA-Z0-9//\n\/\.\:\+\ \=]+).*(-----END PGP PUBLIC KEY BLOCK-----)$/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment