RSA Key Pair Generator
Generate an RSA public and private key pair in your browser, 2048 or 4096 bit, with no server involved. Pick a key size and click Generate — the keys appear below as PEM text you can copy or download. Your keys are created on your own device and are never sent anywhere.
Your key pair
Keys are generated with the browser Web Crypto API, using RSA-OAEP with SHA-256. Nothing leaves your device. Save the private key somewhere safe as soon as it appears — it is shown once and this page keeps no copy.
Your keys
Pick a key size and click Generate Key Pair to create your keys.
What Is an RSA Key Pair?
An RSA key pair is two mathematically linked keys: a public key and a private key. The public key can be shared freely — anyone can use it to encrypt a message meant for you, or to check a digital signature you made. The private key must stay secret — only its owner can decrypt those messages or create those signatures. RSA is named after its inventors, Rivest, Shamir, and Adleman, and it is one of the most widely used public-key systems, found in secure web connections, email encryption, SSH logins, and code signing.
How RSA Key Generation Works
This tool uses only the browser built-in Web Crypto API, so no key material ever travels over the network. When you click Generate, the browser calls crypto.subtle.generateKey with RSA-OAEP and SHA-256, a modulus length of 2048 or 4096 bits, and the standard public exponent 65537. The browser picks two large random prime numbers, multiplies them to form the modulus, and derives the public and private exponents from them. The keys are then exported in standard formats — the public key as SPKI and the private key as PKCS#8 — and each is encoded in base64, wrapped at 64 characters per line, and placed between PEM header and footer lines. A 4096-bit key uses larger primes and takes noticeably longer to create than a 2048-bit key, which is why the button shows a Generating state while it works.
Worked Example
Example, with a 2048-bit key pair generated by this tool. The public key, exported in SPKI format, is 294 bytes of data, encoded as 392 base64 characters wrapped into 7 lines of 64 characters or fewer, between the lines -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----. The private key, exported in PKCS#8 format, is about 1,217 bytes of data, encoded as about 1,624 base64 characters wrapped into 26 lines, between the lines -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----. The exact characters are different every time, because each key pair is freshly generated from random primes. A 4096-bit pair is larger: its public key is 550 bytes of data and its private key is about 2,375 bytes, so both PEM blocks are roughly twice as long.
Common Mistakes
Sharing the private key. Anyone with the private key can read your encrypted messages and pretend to be you. Never paste it into a website, a chat message, an email, or a public code repository. If a private key is ever exposed, stop using that key pair and generate a fresh one.
Losing the only copy of the private key. This page keeps no copy of your keys, and there is no way to recover a lost private key — the matching public key cannot recreate it. Download the private key file and store it somewhere safe, such as an encrypted drive or a password manager, before you close the page.
Using a key that is too small. 1024-bit RSA keys are no longer considered safe. This tool only offers 2048-bit and 4096-bit keys, which are the sizes recommended today: 2048-bit for most uses, 4096-bit where extra strength is worth the slower speed.
Mixing up the two keys. Encrypt with the public key and decrypt with the private key. Publishing the private key by mistake, or trying to decrypt with the public key, does not work and can leak the secret. Check the header line — PUBLIC KEY or PRIVATE KEY — before you share or paste either block.
Generating keys on a shared computer and leaving the files behind. On a computer other people use, download the private key, move it to safe storage, and delete the downloaded file from the shared machine. A private key left in a downloads folder is as good as shared.
Related Tools
Convert between units with the Unit Converter, work out a percentage of any number with the Percentage Calculator, find the days between two dates with the Date Calculator, and count down to an important date with the Countdown Timer.
Frequently Asked Questions
What is an RSA key pair used for?
Two main jobs: encryption and digital signatures. Anyone can encrypt a message with your public key, and only you, holding the private key, can decrypt it. In the other direction, you sign data with your private key, and anyone can verify the signature with your public key. RSA keys are used in secure websites, SSH logins, encrypted email, and signed software updates.
Is it safe to generate keys in my browser?
Yes, when the tool uses the built-in Web Crypto API, as this one does. The keys are created inside your browser by your own device, using its random number generator, and they are never sent to a server — this page makes no network request at all during generation. The risk is not the generation, it is storage: keep the private key file somewhere safe and never share it.
What is the difference between 2048-bit and 4096-bit keys?
4096-bit keys are stronger against future attacks but slower to generate and slower to use, and their PEM text is about twice as long. 2048-bit RSA is the standard choice today and is recommended for most uses. Choose 4096-bit when the key must stay safe for many years or when a service you use specifically asks for it.
What format are the keys in?
PEM text: base64 data wrapped at 64 characters per line, between BEGIN and END header lines. The public key uses the SPKI format, starting with -----BEGIN PUBLIC KEY-----, and the private key uses the PKCS#8 format, starting with -----BEGIN PRIVATE KEY-----. Both formats are accepted by OpenSSL, SSH tools, and most servers and libraries.
Can I recover a private key if I lose it?
No. A private key cannot be rebuilt from its public key — that is the whole point of RSA. If you lose the private key, anything encrypted to that public key can never be decrypted, and any signatures from that key can never be made again. Generate a new key pair and replace the public key wherever the old one was used.
Why does the page say it must be served over HTTPS?
Browsers only expose the Web Crypto API on secure pages, which means HTTPS or a local address. On a plain HTTP page the API is unavailable, so key generation cannot run. If you see that message, open the page over HTTPS and try again.