RSA Key Generator
/rsa-key-generator/
Related tools
Comments
About this tool
When you need an RSA key pair
RSA is a public-key cryptosystem published in 1977 by Ronald Rivest, Adi Shamir and Leonard Adleman at MIT, and its name comes from their initials. A public key and a private key form a pair: anyone can verify a signature made with the private key using the public key, and data encrypted with the public key can be decrypted only with the private key.
Read moreShow less
In development work RSA key pairs are needed more often than you might expect: authentication servers that sign JWTs with RS256, verifying signatures on webhook requests, encrypting messages between services, local TLS test environments, and unit tests for a library's signing features. This RSA key generator lets you get keys straight from the browser instead of looking up OpenSSL options each time.
Choose a key size of 2048, 3072 or 4096 bits and press Generate, and the private and public keys appear in PEM format, ready to download as private.pem and public.pem.
How the RSA key generator uses WebCrypto, and the PEM format
Keys are generated with crypto.subtle.generateKey from the browser's built-in WebCrypto. Internally, two large random primes, each half the key size, are found and multiplied to form the modulus, and the public exponent is the standard value 65537. 65537 is the prime 2^16 + 1, which has only two 1 bits in binary, so signature verification and encryption are fast while the weaknesses of very small exponents are avoided.
The private key is exported as DER bytes in the PKCS#8 structure and the public key in the SPKI (SubjectPublicKeyInfo) structure, then converted to Base64 with a line break every 64 characters to form PEM. That is why the private key starts with -----BEGIN PRIVATE KEY----- and the public key with -----BEGIN PUBLIC KEY-----. Because the structure is fixed, a 2048-bit public key always starts with MIIBIjANBgkqhkiG9w0BAQEFAAOC, a fixed header holding the 'RSA public key' algorithm identifier and length information. The keys carry the generic RSA algorithm identifier, so libraries such as OpenSSL, Node.js, Java and Python's cryptography read them as they are.
Finding primes means picking random candidates and testing them repeatedly, so the time varies with key size and with luck. In measurements on one computer, 2048 bits took around 0.1 seconds, while five 4096-bit runs ranged from about 0.2 to 2.5 seconds. On an older phone 4096 bits can take several seconds, and the button shows Generating… while it works.
Choosing an RSA key size and putting the keys to use
The US NIST classifies RSA 2048 as 112-bit security strength and RSA 3072 as 128-bit. 112-bit strength is recommended for use through 2030, so 2048 bits is enough for a key created now and replaced within a few years. For keys that will be used beyond 2030, or that must last a long time, such as signatures on archived documents, 3072 bits or more is the safer choice.
4096 bits gives a large security margin, but signing becomes noticeably slower and keys and signatures grow. Just the PEM public key is 451 characters at 2048 bits, 625 at 3072 and 800 at 4096. For an API server signing thousands of tokens per second, that difference becomes cost, so where performance matters consider 3072 bits or elliptic-curve schemes (ES256, Ed25519).
You can confirm that a downloaded key is sound with openssl pkey -in private.pem -text -noout; seeing the modulus and the public exponent 65537 means it is fine. To convert the public key to OpenSSH's ssh-rsa format, use ssh-keygen -i -m PKCS8 -f public.pem, and if an older library accepts only the PKCS#1 format starting with -----BEGIN RSA PRIVATE KEY-----, convert it with OpenSSL.
Handling the private key safely
Keys are created inside this browser and never sent to a server. The generated private key exists only on screen and in page memory, and disappears when you close the page or press Reset; the only thing kept in this browser for next time is your key size choice. Even so, production TLS keys and real signing keys should be created on the server itself, or inside a key management service such as AWS KMS or a hardware security module, and never taken out; this tool suits development, testing and learning.
The downloaded private.pem is an unencrypted plaintext key. Do not commit it to a Git repository or send it over a messenger; if you must keep it, restrict file permissions so only you can read it, or protect it with a passphrase using openssl pkcs8 -topk8. Copy puts both the private and public keys on the clipboard at once, so when you only mean to hand over the public key, downloading public.pem separately avoids mistakes.
This tool generates key pairs only; it does not create certificate signing requests (CSRs), self-signed certificates, passphrase-protected private keys or OpenSSH-format keys. RSA is known to be breakable by Shor's algorithm on a sufficiently large quantum computer, regardless of key size, and NIST published post-quantum cryptography standards in 2024 and recommends preparing for a long-term transition.
Popular tools
FAQ
Is the RSA key I generate sent to a server?
No. It is created on this device with the browser's WebCrypto and sent nowhere. The key also disappears when you close the page, so download the keys you need right away.
What RSA key size should I choose?
2048 bits is enough for typical keys replaced within a few years. Choose 3072 bits or more for keys used beyond 2030 or with higher security requirements. 4096 bits makes generation and signing slower, so use it only when you really need it.
Can it create OpenSSH format (ssh-rsa) keys?
This tool produces PEM only (PKCS#8 and SPKI). The public key can be converted to OpenSSH format with ssh-keygen -i -m PKCS8 -f public.pem. For SSH login keys, running ssh-keygen directly is usually the most direct route.
What is the difference between BEGIN PRIVATE KEY and BEGIN RSA PRIVATE KEY?
BEGIN PRIVATE KEY is the PKCS#8 format, which can hold keys for several algorithms, while BEGIN RSA PRIVATE KEY is the RSA-only PKCS#1 format. This tool exports PKCS#8, which most modern libraries read.
Can I use these keys for JWT RS256 signing?
Yes. The keys are generated with settings for SHA-256 signatures. Node.js's jsonwebtoken accepts the PEM as is, and in Java you strip the header lines, decode the Base64 and load it with PKCS8EncodedKeySpec or X509EncodedKeySpec. Production signing keys, however, are best created on the server or in a key management service.
Why does a 4096-bit key take so long?
Two large primes, each half the key size, must be found among random candidates. The bigger the numbers, the more work each test takes and the lower the chance of hitting a prime, so the time varies from run to run even on the same device.