An RSA key generator example for OAEP consists of a matching SPKI public-key PEM and PKCS#8 private-key PEM, using SHA-256 and exponent 65537.

The actual key bytes should be random, so a safe example can show the required formats and workflow without publishing reusable private-key material. The RSA Key Generator creates a fresh pair in the browser, exports both PEM envelopes, and does not send key bytes to the application server. Generating twice with identical settings produces different keys.

rsa key generator example
RSA Key Generator: Private Key Handoff and Testing

Set the RSA-OAEP parameters correctly

A generated key is useful only when the application on the other end uses compatible algorithms and accepts the exported envelope. Check the protocol before generating anything. The PEM file identifies the key structure, but it does not make an incompatible encryption implementation work.

Setting Supported value Why it matters
Encryption algorithm RSA-OAEP The key is for encryption and decryption, not digital signatures.
OAEP hash SHA-256 The encrypting and decrypting systems must use the same hash.
Public exponent 65537 The receiving system must expect this fixed exponent.
Public-key envelope SPKI PEM The public key begins with the PUBLIC KEY boundary.
Private-key envelope PKCS#8 PEM The private key begins with the PRIVATE KEY boundary.

In implementation terms, the generator asks the browser’s Web Cryptography API for an RSA-OAEP key with the selected modulus, SHA-256, and exponent 65537. It exports the public key as SPKI DER and the private key as PKCS#8 DER, then wraps each in Base64 PEM at 64 columns.

Choose between a 2048- and 3072-bit modulus

The available sizes serve different priorities. A 2048-bit key is the broadly interoperable choice. A 3072-bit key offers a larger security margin but takes more time to generate and perform cryptographic operations. Neither choice removes the need to protect the private key or test the receiving system.

Modulus size Best fit Tradeoff
2048 bits Compatibility-focused applications Generally faster generation and operations.
3072 bits Applications that prioritize a larger security margin Slower generation and RSA operations, with a different performance profile.

Allow extra time when generating the 3072-bit option. The exact timing depends on the browser and device, so no fixed completion time should be assumed. If the recipient publishes a required modulus length, follow that requirement rather than choosing solely on preference.

Generate the example key pair

  1. Confirm the recipient’s requirements. Verify that the application expects RSA-OAEP with SHA-256, exponent 65537, an SPKI public key, and a PKCS#8 private key. If it asks for a signature, SSH key, certificate, or a different RSA encryption scheme, this generator is not the appropriate workflow.
  2. Open the generator and select the modulus length. Choose 2048 bits for broad interoperability or 3072 bits for a larger security margin. The generation process is asynchronous, and the larger modulus can take additional time.
  3. Generate one pair and wait for both outputs. The result contains a public PEM beginning with -----BEGIN PUBLIC KEY----- and a private PEM beginning with -----BEGIN PRIVATE KEY-----. Do not expect either generation to reproduce an earlier key.
  4. Send only the public key to the encrypting system. The public key can be distributed to the service or recipient that needs to encrypt data for the private-key holder. Treat the public key as an input to the application protocol, not as a secret.
  5. Move the private key directly into protected storage. The exported PKCS#8 private key is unencrypted. Transfer it into an appropriate secret manager or encrypted keystore with strict access controls and backups. Copying it to the clipboard creates a temporary exposure that clipboard managers may preserve.
  6. Run an end-to-end protocol test. Have the encrypting side load the public key, encrypt a small known UTF-8 test message or the application’s supported test envelope, and confirm that the private-key holder recovers the expected plaintext. Repeat the check using the exact OAEP and hybrid-encryption settings required by the application.

If the round trip fails, verify the algorithm, hash, exponent, PEM envelope, OAEP label, and mask-generation settings before generating another pair. Replacing the key can also invalidate a public key that has already been distributed.

Read the PEM output without expecting fixed bytes

A useful example shows the shape of each result rather than pretending that secure generation has one correct answer. The public output has the following structure:

  • Public PEM: -----BEGIN PUBLIC KEY----- followed by Base64-encoded SPKI DER and -----END PUBLIC KEY-----.
  • Private PEM: -----BEGIN PRIVATE KEY----- followed by Base64-encoded PKCS#8 DER and -----END PRIVATE KEY-----.

The boundaries and descriptions above identify the formats, not a usable key pair. The Base64 payload is wrapped at 64 columns. The RFC 7468 textual-encoding specification defines the familiar PEM boundaries, while RFC 8017 specifies the relevant RSA key structures and OAEP mechanisms.

Because secure generation must be random, correctness cannot be checked against a fixed private-key sample. The generator instead re-imports the generated SPKI and PKCS#8 envelopes into Web Crypto, encrypts a known UTF-8 message with the public key, checks exact recovery with the private key, and confirms that the imported algorithm reports the selected modulus length. That local round trip is valuable, but it does not replace testing the external application protocol.

Match OAEP settings at both ends

RSA-OAEP encryption uses the public key, while the mathematically related private key performs decryption. The sender must use the same OAEP hash, label, and mask-generation configuration as the receiver. The generated Web Crypto key uses SHA-256, but another application may default to SHA-1 or expect different OAEP settings.

A successful PEM import only proves that the application can read the key envelope. It does not prove that its encryption parameters agree with the generated key. Run a protocol-level round trip and compare the recovered plaintext exactly.

A common application pattern is to encrypt a fresh symmetric key with RSA-OAEP and protect the actual payload with authenticated symmetric encryption. In that pattern, test both stages: first confirm that the encrypted symmetric key can be recovered with the private key, then confirm that the application’s symmetric-encryption format decrypts and authenticates successfully.

Protect the private key after generation

The PKCS#8 output is not protected by a password envelope. Anyone who obtains it can decrypt compatible ciphertext, so copying the private PEM transfers full responsibility for safeguarding it. Store it only in an appropriate secret manager or encrypted keystore with strict access controls and reliable backups.

Do not place the private key in source control, tickets, chat messages, analytics systems, browser synchronization, or ordinary notes. After securely importing it, close the tab and clear clipboard history where appropriate.

The page keeps the public and private outputs in component memory until navigation or replacement, and it does not transmit key bytes to the application server. That boundary does not protect against malicious browser extensions, compromised endpoints, clipboard managers, or screenshots. Use a trusted, patched device and rotate the key immediately if the private PEM is exposed.

Keep RSA within its data-size limits

RSA can encrypt only a limited amount of data directly. Applications normally encrypt a random symmetric key with RSA-OAEP, then use authenticated symmetric encryption for the larger payload. Do not split a large file into raw RSA blocks and assume that this produces a secure file format.

This generator creates keys only. It intentionally does not define a hybrid file container, so use the application’s established envelope or another separately verified encryption workflow for files and other large data.

Recognize the utility’s boundaries

This example covers RSA-OAEP encryption keys with 2048- or 3072-bit moduli, SHA-256, exponent 65537, SPKI public PEM, and unencrypted PKCS#8 private PEM. The tool does not offer 1024-bit keys, custom public exponents, raw RSA, PKCS#1 v1.5 encryption, or SHA-1.

It is not a certificate authority and does not create X.509 certificates, certificate signing requests, RSA-PSS signatures, SSH keys, or JSON Web Keys. For production identity or TLS, prefer the key-generation workflow supplied by the owning platform or a hardware security module. Format conversion performed later must preserve the required algorithm parameters and the secrecy of the private key.

For a deeper look, see Vigenere Cipher Decoder on iPhone: Key and Copy Workflow.

For a deeper look, see RSA Key Generator Explained: Keys, Formats, and Use.