{"article":{"slug":"horible-public-key-tricks","title":"Horible public key tricks","subtitle":null,"summary":"Maurycy, annoyed at the TLS certificate system, builds an obvious 'protest certificate' by generating a vanity RSA key whose public key spells out readable messages in base64, and explains how it works and its security trade-offs.","content_type":"blog_post","language":"en","canonical_url":"https://maurycyz.com/projects/badcert/","author":{"name":"Maurycy","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"maurycyz.com","url":"https://maurycyz.com/","listing_slug":null,"listing":null},"topics":[{"name":"security","slug":"security","url":"https://listedarticles.com/topics/security"},{"name":"networking","slug":"networking","url":"https://listedarticles.com/topics/networking"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":1121,"reading_minutes":5,"published_at":"2026-11-08T00:00:00.000Z","added_at":"2026-11-10T02:13:14.252Z","updated_at":"2026-11-10T02:13:14.252Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/horible-public-key-tricks","markdown_url":"https://listedarticles.com/articles/horible-public-key-tricks.md","example":false,"citation":"Maurycy, maurycyz.com. \"Horible public key tricks.\" 8 Nov 2026. https://maurycyz.com/projects/badcert/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://maurycyz.com/projects/badcert/"},"body_markdown":"# *Horible public key tricks:*\n\n**2026-11-08** — **2026-11-09**\n\nSo, I've always been somewhat annoyed at SSL/TLS.\nIt requires everyone to go through a complex \"ACME\" dance just to put up a public website.\nWorse, certificates expire every few months, so it's not a one and done thing:\neven with automation, maintaining a certificate requires care to ensure the ACME client always has access to DNS records or the web server.\n\n... and the whole system doesn't even work because certificates are issued over plaintext connections,\nand trusted certificate aurthorities use very secure keys like [\"4\"](https://en.wikipedia.org/wiki/EMudhra)\n\n*There is prior art* of protest SSL [implementations](https://tom7.org/httpv/httpv.pdf),\nbut I do actually want to encrypt web traffic.\nPassive eavesdropping is a real risk... but preventing it doesn't require the whole certificate thing:\ntherefore, the best choice is a protest certificate.\n\nThe only part of the certificate I directly control is the public key.\nTherefore, the simplest way to obtain a bad certificate is use a vanity private key such as 313333333337 (one of the most eleet primes).\nHowever, while the resulting public key would be weak, no one would know unless they try to break it.\n\nA good protest should be obvious:\n\n```\n# openssl s_client -connect maurycyz.com:443 < /dev/null 2> /dev/null \\\n    | sed -n /BEGIN/,/END/p | grep -zE '////.?*////' --color=yes\n\n-----BEGIN CERTIFICATE-----\nMIIFAjCCA+qgAwIBAgISBkOkuuyaN1ypD3PAPrLMyT7tMA0GCSqGSIb3DQEBCwUA\nMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQwwCgYDVQQD\nEwNZUjIwHhcNMjYxMTA5MTcyOTQ2WhcNMjcwMjA3MTcyOTQ1WjAXMRUwEwYDVQQD\nEwxtYXVyeWN5ei5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCg\nJyPf37Sj6PvU06m5////You+dont+actually+have+to+pick+random+privat\ne+keys//No+one+checks+these+things//A+certificate+authority+got+\naway+with+the+number+4+for+a+year/////DSfCAfXcsJfBpnHekS0qnf5YLl\nc54VuUNRVINcDkEwJDwyB96+xE/uXhtiGdk8ty1PF6jciLEYCJBHcmqOa5pOyV8m\n63yR3NE6hCQlaSLQQDo96Sb0/10aC5LqE7KwEskrP/qeCzT7vDN7fh+dXOGs+VMw\neJvTAb0xHJpxhSK05i7DAgMBAAGjggIqMIICJjAOBgNVHQ8BAf8EBAMCBaAwEwYD\nVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUBKBfDbwf\ndCnKeU83pMTWyFrJBwAwHwYDVR0jBBgwFoAUQBUtJnntMiCe35pyHdYyH4EMgQww\nMwYIKwYBBQUHAQEEJzAlMCMGCCsGAQUFBzAChhdodHRwOi8veXIyLmkubGVuY3Iu\nb3JnLzAnBgNVHREEIDAegg4qLm1hdXJ5Y3l6LmNvbYIMbWF1cnljeXouY29tMBMG\nA1UdIAQMMAowCAYGZ4EMAQIBMC8GA1UdHwQoMCYwJKAioCCGHmh0dHA6Ly95cjIu\nYy5sZW5jci5vcmcvMTEwLmNybDCCAQsGCisGAQQB1nkCBAIEgfwEgfkA9wB1AExj\n3JjlnB2riPYeij3ero+rRKM3e1+blMP7oZz8wb4mAAABocGRbw4AAAQDAEYwRAIg\nHShWaEI2nVJEizSI6sJ/jnLaABZ3aTKoUL3pLo1uOgsCIEn+XiT2WHhm9LGN6kug\nO9R7Z4q0HiFA4RZ7tIMJQH5XAH4AjspHC6zeavOiBrCkeoS3Rv4fxr+VPiXmm07k\nAkjzxugAAAGhwZFyfQAIAAAFAEE0hdwEAwBHMEUCIDSms4Vf0llcvcldJd2Ool8i\nAiUQQlS0Zzbej+7Y1aR7AiEA79Ll+t6inu1PkUIgzNTXkE0S20VHYEYel5fkdKSA\nVTQwDQYJKoZIhvcNAQELBQADggEBAFi3A4fcjj4UKa9MFz1a8DWc+Jya2gJng13m\n2UFdWCaqsN7FJWQEjRiJ0npynmDnA3VMyjswUMHAMx4d8G3lHNPfZWGsCgpjVa/d\nIEoeZ6gTYjFa/Ovb64m4CcuQkm0GxcyAqMPs348e6Px32iU1R6MnV4UEUosnSPeK\n4ocuI3SoR9LHxX/yHOKcYTKLpIMwMdaAmWt0N7l59GOb8o+dz3R7cxtVV/lrZReZ\n/YPEAYRiNi7f+jNI1JCp0i8wXUb9NN7WlbmcFDecDG/++cRpAkoIk4m/LJindsuu\nkErrVZ4yLqB0Hvm+uNvWxr9y/qKFTYw9POx1oaZJO/SwXZdDBeY=\n-----END CERTIFICATE-----\n```\n\n*First, let's look at mathematical framework* of RSA.\nTo generate a key, pick two large prime numbers (p and q) and multiply them to yeild the modulus (n).\nPick a small number, e as public exponent.\n\nThe RSA public key is composed of the modulus (n) and the public exponent:\n\n```\n# Encryption requires knowing e (public)\ncyphertext = plaintext^e mod n\n```\n\nThe private key contains the modulus and the private exponent (d) which is chosen to be the multiplicate inverse of e modulo n.\nExactly how d is found is not relevent, but the process requires knowing p and q.\n\n```\n# Decryption requires knowing d (pivate)\n= cyphertext^d mod n\n\n= plaintext^e^d mod n\n= plaintext^(e*d) mod n\n= plaintext^1 mod n\n= plaintext\n```\n\n*Ok, back to vanity keys.*\nThe standard value for e is 65537 (0x10001),\nbecause the small number of set bits makes encryption faster.\nIn fact, the CA I used will refuse to sign keys with a non-standard public exponent, so I can't do anything funny there.\n\nThe modulus, n, is either 2,048 or 4,096 \"user controlled\" bits, so it's the ideal place to hide a message.\nHowever, to use the certificate, I'll need to find two large primes that multiply out to the vanity modulus.\n\nMy method starts by picking two random primes and calculating the resulting n value.\nThen, the bytes of n are modified to introduce message into the base64 encoding.\nOf course, the modified n is not the product of p and q, but this is fixable by setting q to n/p.\n\nThe resulting q value is very unlikely to be a prime (or integer), so I round it and find the next prime after the ideal q:\nwhich usually only requires changing the value of q by a few hundred.\nSince p and q are similar in size, a small change q only affects the least-sigifiant half of the product:\n\n```\n58174124 * 918491824 = 53432457262362176\n(incrementing until the next prime...)\n58174124 * 918491843 = 53432458367670532\n```\n\nAs long as the message is embedded into the upper half of n, it's likely to survive undamaged.\nThe original p and newly selected q can now be used to construct a functional RSA private key in the usual manner.\n\nFrom here, it's really just a matter of getting a certificate aurthority to sign the key:\n\n```\n# Single domain\nopenssl req -new -key priv.pem -subj '/C=US/CN=example.com' > cert_request\ncertbot certonly --manual --csr cert_request\n\n# Wildcard\ncat > config<<EOF\n[ req ]\nreq_extensions = req_ext\n\n[ req_ext ]\nsubjectAltName = @alt_names\n\n[ alt_names ]\nDNS.1 = *.example.com\nDNS.2 = example.com\nEOF\nopenssl req -new -key priv.pem -config config -subj '/C=US/CN=example.com' > cert_request\ncertbot certonly --manual --csr cert_request\n```\n\n... although since base64 operates on groups of three byte,\nit is possible for the message to be misaligned and not readable.\nHowever, since the layout of the certificate is static, it is possible to adjust the message's placement until it works:\nthis should take less than four attempts.\n\nThe result is a functional, trusted certificate with a longish message hidden in the public key.\nRenewal is done by resumbitting the CSR and repeating the ACME chalange, which can be automated.\n\nBase64 is missing most punctuation, but it provides the full ASCII alphabet,\nand the ~150 (RSA-2048) or ~320 (RSA-4096) avalable charaters provides plenty of space for jokes.\nAnother option would be to target the base16 displayed in most browser's certificate viewer:\nthis would provide a lot more space (2 chars/byte instea of 0.75), but requires careful word choice.\n\n*As for security*, this trick obviously reduces the entropy in the private key.\nHowever, it should still be secure:\nnearly identical methods have been considered as a form of compression.\nIf the top-half of the modulus is fixed to a well known value, it doesn't have to be sent or stored as part of the key.\n\nA reduction of around 1/2 can be achieved through division, but the state of the art can\nfix 2/3 of the key, reducing the size to 1/3 of standard RSA while retaining a similar level of security...\nalthough I should note that such tricks have largly been abandoned in favor of other crytosystems which can directly use small keys.\n\nThe manipulation of q may produce primes that are very close together, which makes it possible to factor n and recover the private key.\nA very small d value can also be a problem.\nBoth of these are unlikely, but my script doesn't check for insecure values\n\nHowever, regardless of the key's security, it should be perfectly fine for a public website:\nmodern TLS provides forward secrecy, so eavesdropping requires a man-in-the-middle attack even if the private key is compromised.\n\n# *Related*:\n\n- <https://tom7.org/httpv/httpv.pdf>: [⭐ World's worst TLS server ]\n- [/projects/badcert/gen.py](https://maurycyz.com/projects/badcert/gen.py): script to generate a vanity key\n- <https://rya.nc/cert-tricks.html>: More vanity certs\n- <https://doi.org/10.1007/978-3-540-79104-1_9>: Actual cryptographer's opinions on fixing part of n\n","body_html":"<h1 id=\"horible-public-key-tricks\"><em>Horible public key tricks:</em></h1>\n<p><strong>2026-11-08</strong> — <strong>2026-11-09</strong></p>\n<p>So, I&#39;ve always been somewhat annoyed at SSL/TLS.\nIt requires everyone to go through a complex &quot;ACME&quot; dance just to put up a public website.\nWorse, certificates expire every few months, so it&#39;s not a one and done thing:\neven with automation, maintaining a certificate requires care to ensure the ACME client always has access to DNS records or the web server.</p>\n<p>... and the whole system doesn&#39;t even work because certificates are issued over plaintext connections,\nand trusted certificate aurthorities use very secure keys like <a href=\"https://en.wikipedia.org/wiki/EMudhra\" rel=\"nofollow ugc noopener\">&quot;4&quot;</a></p>\n<p><em>There is prior art</em> of protest SSL <a href=\"https://tom7.org/httpv/httpv.pdf\" rel=\"nofollow ugc noopener\">implementations</a>,\nbut I do actually want to encrypt web traffic.\nPassive eavesdropping is a real risk... but preventing it doesn&#39;t require the whole certificate thing:\ntherefore, the best choice is a protest certificate.</p>\n<p>The only part of the certificate I directly control is the public key.\nTherefore, the simplest way to obtain a bad certificate is use a vanity private key such as 313333333337 (one of the most eleet primes).\nHowever, while the resulting public key would be weak, no one would know unless they try to break it.</p>\n<p>A good protest should be obvious:</p>\n<pre><code># openssl s_client -connect maurycyz.com:443 &lt; /dev/null 2&gt; /dev/null \\\n    | sed -n /BEGIN/,/END/p | grep -zE &#39;////.?*////&#39; --color=yes\n\n-----BEGIN CERTIFICATE-----\nMIIFAjCCA+qgAwIBAgISBkOkuuyaN1ypD3PAPrLMyT7tMA0GCSqGSIb3DQEBCwUA\nMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQwwCgYDVQQD\nEwNZUjIwHhcNMjYxMTA5MTcyOTQ2WhcNMjcwMjA3MTcyOTQ1WjAXMRUwEwYDVQQD\nEwxtYXVyeWN5ei5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCg\nJyPf37Sj6PvU06m5////You+dont+actually+have+to+pick+random+privat\ne+keys//No+one+checks+these+things//A+certificate+authority+got+\naway+with+the+number+4+for+a+year/////DSfCAfXcsJfBpnHekS0qnf5YLl\nc54VuUNRVINcDkEwJDwyB96+xE/uXhtiGdk8ty1PF6jciLEYCJBHcmqOa5pOyV8m\n63yR3NE6hCQlaSLQQDo96Sb0/10aC5LqE7KwEskrP/qeCzT7vDN7fh+dXOGs+VMw\neJvTAb0xHJpxhSK05i7DAgMBAAGjggIqMIICJjAOBgNVHQ8BAf8EBAMCBaAwEwYD\nVR0lBAwwCgYIKwYBBQUHAwEwDAYDV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O/SwXZdDBeY=\n-----END CERTIFICATE-----</code></pre>\n<p><em>First, let&#39;s look at mathematical framework</em> of RSA.\nTo generate a key, pick two large prime numbers (p and q) and multiply them to yeild the modulus (n).\nPick a small number, e as public exponent.</p>\n<p>The RSA public key is composed of the modulus (n) and the public exponent:</p>\n<pre><code># Encryption requires knowing e (public)\ncyphertext = plaintext^e mod n</code></pre>\n<p>The private key contains the modulus and the private exponent (d) which is chosen to be the multiplicate inverse of e modulo n.\nExactly how d is found is not relevent, but the process requires knowing p and q.</p>\n<pre><code># Decryption requires knowing d (pivate)\n= cyphertext^d mod n\n\n= plaintext^e^d mod n\n= plaintext^(e*d) mod n\n= plaintext^1 mod n\n= plaintext</code></pre>\n<p><em>Ok, back to vanity keys.</em>\nThe standard value for e is 65537 (0x10001),\nbecause the small number of set bits makes encryption faster.\nIn fact, the CA I used will refuse to sign keys with a non-standard public exponent, so I can&#39;t do anything funny there.</p>\n<p>The modulus, n, is either 2,048 or 4,096 &quot;user controlled&quot; bits, so it&#39;s the ideal place to hide a message.\nHowever, to use the certificate, I&#39;ll need to find two large primes that multiply out to the vanity modulus.</p>\n<p>My method starts by picking two random primes and calculating the resulting n value.\nThen, the bytes of n are modified to introduce message into the base64 encoding.\nOf course, the modified n is not the product of p and q, but this is fixable by setting q to n/p.</p>\n<p>The resulting q value is very unlikely to be a prime (or integer), so I round it and find the next prime after the ideal q:\nwhich usually only requires changing the value of q by a few hundred.\nSince p and q are similar in size, a small change q only affects the least-sigifiant half of the product:</p>\n<pre><code>58174124 * 918491824 = 53432457262362176\n(incrementing until the next prime...)\n58174124 * 918491843 = 53432458367670532</code></pre>\n<p>As long as the message is embedded into the upper half of n, it&#39;s likely to survive undamaged.\nThe original p and newly selected q can now be used to construct a functional RSA private key in the usual manner.</p>\n<p>From here, it&#39;s really just a matter of getting a certificate aurthority to sign the key:</p>\n<pre><code># Single domain\nopenssl req -new -key priv.pem -subj &#39;/C=US/CN=example.com&#39; &gt; cert_request\ncertbot certonly --manual --csr cert_request\n\n# Wildcard\ncat &gt; config&lt;&lt;EOF\n[ req ]\nreq_extensions = req_ext\n\n[ req_ext ]\nsubjectAltName = @alt_names\n\n[ alt_names ]\nDNS.1 = *.example.com\nDNS.2 = example.com\nEOF\nopenssl req -new -key priv.pem -config config -subj &#39;/C=US/CN=example.com&#39; &gt; cert_request\ncertbot certonly --manual --csr cert_request</code></pre>\n<p>... although since base64 operates on groups of three byte,\nit is possible for the message to be misaligned and not readable.\nHowever, since the layout of the certificate is static, it is possible to adjust the message&#39;s placement until it works:\nthis should take less than four attempts.</p>\n<p>The result is a functional, trusted certificate with a longish message hidden in the public key.\nRenewal is done by resumbitting the CSR and repeating the ACME chalange, which can be automated.</p>\n<p>Base64 is missing most punctuation, but it provides the full ASCII alphabet,\nand the ~150 (RSA-2048) or ~320 (RSA-4096) avalable charaters provides plenty of space for jokes.\nAnother option would be to target the base16 displayed in most browser&#39;s certificate viewer:\nthis would provide a lot more space (2 chars/byte instea of 0.75), but requires careful word choice.</p>\n<p><em>As for security</em>, this trick obviously reduces the entropy in the private key.\nHowever, it should still be secure:\nnearly identical methods have been considered as a form of compression.\nIf the top-half of the modulus is fixed to a well known value, it doesn&#39;t have to be sent or stored as part of the key.</p>\n<p>A reduction of around 1/2 can be achieved through division, but the state of the art can\nfix 2/3 of the key, reducing the size to 1/3 of standard RSA while retaining a similar level of security...\nalthough I should note that such tricks have largly been abandoned in favor of other crytosystems which can directly use small keys.</p>\n<p>The manipulation of q may produce primes that are very close together, which makes it possible to factor n and recover the private key.\nA very small d value can also be a problem.\nBoth of these are unlikely, but my script doesn&#39;t check for insecure values</p>\n<p>However, regardless of the key&#39;s security, it should be perfectly fine for a public website:\nmodern TLS provides forward secrecy, so eavesdropping requires a man-in-the-middle attack even if the private key is compromised.</p>\n<h1 id=\"related\"><em>Related</em>:</h1>\n<ul><li><a href=\"https://tom7.org/httpv/httpv.pdf\" rel=\"nofollow ugc noopener\">https://tom7.org/httpv/httpv.pdf</a>: [⭐ World&#39;s worst TLS server ]</li><li><a href=\"https://maurycyz.com/projects/badcert/gen.py\" rel=\"nofollow ugc noopener\">/projects/badcert/gen.py</a>: script to generate a vanity key</li><li><a href=\"https://rya.nc/cert-tricks.html\" rel=\"nofollow ugc noopener\">https://rya.nc/cert-tricks.html</a>: More vanity certs</li><li><a href=\"https://doi.org/10.1007/978-3-540-79104-1_9\" rel=\"nofollow ugc noopener\">https://doi.org/10.1007/978-3-540-79104-1_9</a>: Actual cryptographer&#39;s opinions on fixing part of n</li></ul>","headings":[{"level":1,"text":"*Horible public key tricks:*","id":"horible-public-key-tricks"},{"level":1,"text":"*Related*:","id":"related"}]}}