# Embedding Custom Messages into RSA Public Keys

Manipulating RSA modulus values to hide text within trusted SSL/TLS certificates.

- **Source:** [Hacker News: Front Page](https://brifing.si/source/b07aa772-b1a0-4a76-aa18-719c6f9e2dde)
- **Published:** 2026-11-10
- **Topic:** [technology](https://brifing.si/c/technology)
- **Original article:** <https://maurycyz.com/projects/badcert/>
- **On Brifing:** https://brifing.si/s/1603341e-c9e0-4b46-9945-8426e0aeceac

## The Vanity Key Concept

The author proposes embedding custom text messages directly into the public key of an SSL/TLS certificate. By manipulating the RSA modulus, one can force specific characters to appear within the base64 representation of the key. This process leverages the static nature of certificate layouts to ensure the hidden message remains readable.

## RSA Mathematical Foundations

RSA encryption relies on a modulus n, which is the product of two large primes, p and q. The author generates a vanity modulus by selecting p and then calculating an ideal q to match the desired message. Adjusting q slightly allows the modulus to retain its mathematical validity for standard encryption.

## Maintaining Cryptographic Integrity

While modifying the modulus, the author must ensure the resulting q remains a prime number. By incrementing the value of q until a prime is found, the product n remains functional. This adjustment typically only affects the least-significant half of the modulus, preserving the integrity of the message embedded in the upper half.

## Certificate Authority Constraints

Certificate Authorities often enforce strict standards, such as requiring a standard public exponent of 65537. Because the author cannot alter this exponent, all vanity modifications are confined to the modulus. The process involves submitting a custom Certificate Signing Request (CSR) to an authority, which then signs the manipulated, yet technically valid, key.

## Security and Entropy Risks

Embedding messages reduces the entropy of the private key, potentially introducing vulnerabilities. If the primes p and q become too close in value, the modulus becomes easier to factor, compromising the key. Furthermore, the author notes that their current script does not perform checks to prevent the generation of insecure, weak keys.

## Forward Secrecy Mitigations

Despite potential weaknesses in the static public key, the author argues the method is safe for public websites. Modern TLS implementations utilize forward secrecy, which ensures that even if a private key is eventually compromised, past traffic remains encrypted. This mechanism protects historical data from retroactive decryption by a man-in-the-middle attacker.

## Base64 and Display Limitations

The visibility of the embedded message depends on the encoding format. Base64 provides limited space and lacks punctuation, while targeting the base16 representation in browser certificate viewers offers more character capacity. Misalignment issues are common, but the author suggests that message placement can be corrected within fewer than four iterative attempts.

## Historical Context of Compression

Techniques for fixing parts of an RSA key to reduce size have historical precedents in cryptographic research. While some methods can reduce key size to one-third of standard RSA, these approaches have largely been abandoned. Modern systems now favor alternative cryptosystems that natively support smaller keys without requiring such complex manual manipulation.

## Sources covering this story

- https://maurycyz.com/projects/badcert/ — 

---

_Summary written by Brifing from the original reporting. Copyright in the original article belongs to its publisher; read the full piece at the link above._
