RSA-OAEP Encrypt & Decrypt Online | PEM PKCS#8 Public Key
Encryption How It Works
What Is RSA-OAEP Encryption?
RSA-OAEP (Optimal Asymmetric Encryption Padding) is the recommended padding scheme for RSA encryption, replacing the deprecated PKCS#1 v1.5. RSA is an asymmetric encryption algorithm that uses a pair of mathematically linked keys — the public key encrypts data, and only the corresponding private key can decrypt it.
This tool provides RSA-OAEP encryption and decryption using the browser's built-in Web Crypto API. The tool includes a built-in key generator, key inspector, and PKCS#8/PKCS#1 format conversion. All cryptographic operations run locally — your keys and data never leave your device.
When to Use RSA-OAEP
- Hybrid encryption — Use RSA to encrypt a symmetric key (AES-256), then use AES for bulk data encryption
- Key exchange — Securely transmit symmetric keys over untrusted channels
- Digital signatures — RSA can also be used for signing (though ECDSA/Ed25519 are preferred for new systems)
- Small data encryption — Encrypt data smaller than key size minus padding overhead (190 bytes for RSA-2048 with SHA-256)
- Legacy system compatibility — RSA is widely supported across all platforms and languages
- When NOT to use — For bulk data encryption, use AES-256-GCM instead; RSA is 1000x slower and has size limits
RSA Key Size & Capacity
Maximum plaintext size with SHA-256 OAEP padding (key size − 66 bytes overhead):
| Key Size | Max Plaintext | Security Level | Recommended |
|---|---|---|---|
| RSA-2048 | 190 bytes | 112-bit | Minimum acceptable |
| RSA-3072 | 318 bytes | 128-bit | Recommended for most use |
| RSA-4096 | 446 bytes | 152-bit | High-security applications |
Standards Compliance
- RFC 8017 — PKCS #1: RSA Cryptography Specifications Version 2.2
- NIST SP 800-56B — Key Pair Establishment using RSA
- NIST FIPS 186-5 — Digital Signature Standard (DSS)
- Web Crypto API — W3C Recommendation for RSA-OAEP (2017)
Last updated:
Code Examples
Encrypt and decrypt with RSA-OAEP using well-audited libraries:
JavaScript — Web Crypto API (Browser)
// Generate RSA-OAEP key pair
const keyPair = await crypto.subtle.generateKey(
{
name: 'RSA-OAEP',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'SHA-256'
},
true,
['encrypt', 'decrypt']
);
// Encrypt with public key
const plaintext = new TextEncoder().encode('secret message');
const ciphertext = await crypto.subtle.encrypt(
{ name: 'RSA-OAEP' },
keyPair.publicKey,
plaintext
);
// Decrypt with private key
const decrypted = await crypto.subtle.decrypt(
{ name: 'RSA-OAEP' },
keyPair.privateKey,
ciphertext
);
console.log(new TextDecoder().decode(decrypted)); Python — cryptography library
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import hashes
# Generate RSA key pair
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048
)
public_key = private_key.public_key()
# Encrypt with public key (OAEP padding)
plaintext = b'secret message'
ciphertext = public_key.encrypt(
plaintext,
padding.OAEP(
mgf=padding.MGF1(hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
# Decrypt with private key
decrypted = private_key.decrypt(
ciphertext,
padding.OAEP(
mgf=padding.MGF1(hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
print(f'Decrypted: {decrypted.decode()}') Go — crypto/rsa
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"fmt"
)
func main() {
// Generate RSA key pair
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048)
publicKey := &privateKey.PublicKey
// Encrypt with public key (OAEP)
plaintext := []byte("secret message")
label := []byte("")
ciphertext, _ := rsa.EncryptOAEP(
sha256.New(),
rand.Reader,
publicKey,
plaintext,
label
)
// Decrypt with private key
decrypted, _ := rsa.DecryptOAEP(
sha256.New(),
rand.Reader,
privateKey,
ciphertext,
label
)
fmt.Printf("Decrypted: %s\n", decrypted)
} Rust — rsa crate
use rsa::{
pkcs1v15::SigningKey,
pss::{BlindingRng, Signature},
Oaep, RsaPrivateKey, RsaPublicKey,
};
use sha2::Sha256;
use rand::rngs::OsRng;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate RSA key pair
let mut rng = OsRng;
let private_key = RsaPrivateKey::new(&mut rng, 2048)?;
let public_key = RsaPublicKey::from(&private_key);
// Encrypt with public key (OAEP)
let padding = Oaep::new::<Sha256>();
let plaintext = b"secret message";
let ciphertext = public_key.encrypt(&mut rng, padding, plaintext.as_ref())?;
// Decrypt with private key
let decrypted = private_key.decrypt(padding, &ciphertext)?;
println!("Decrypted: {}", String::from_utf8(decrypted)?);
Ok(())
} Node.js — crypto module
const crypto = require('crypto');
// Generate RSA key pair
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
});
// Encrypt with public key (OAEP)
const plaintext = 'secret message';
const ciphertext = crypto.publicEncrypt(
{
key: publicKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256'
},
Buffer.from(plaintext)
);
// Decrypt with private key
const decrypted = crypto.privateDecrypt(
{
key: privateKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha256'
},
ciphertext
);
console.log('Decrypted:', decrypted.toString()); Common Pitfalls & Attack Vectors
Security Notes
Disclaimer
Disclaimer: This page is for educational and testing purposes only. It does not constitute professional security advice. For production encryption systems, consult official standards (RFC 8017, NIST SP 800-56B) and conduct a formal security review.
Further Reading & Standards
- RFC 8017 — PKCS #1: RSA Cryptography Specifications Version 2.2
- NIST SP 800-56B — Recommendation for Pair-Wise Key-Establishment Using Integer Factorization Cryptography
- NIST FIPS 186-5 — Digital Signature Standard (DSS)
- Web Crypto API — W3C Recommendation: Web Cryptography API
Related Concepts
- RSA Encryption Explained — How RSA works, key generation, and security considerations
- Symmetric vs Asymmetric Encryption — Understanding when to use RSA vs AES
- Key Management — Best practices for generating and protecting RSA keys
- Digital Signatures — How RSA can be used for signing (though ECDSA is preferred)
Related Tools
Need to generate RSA key pairs? The RSA Key Generator creates PEM-formatted keys with configurable parameters. To convert between PKCS#1 and PKCS#8 formats, try the PEM Format Converter. For hybrid encryption workflows, combine with AES Encrypt/Decrypt.
Frequently Asked Questions
How does RSA encryption work?
RSA is an asymmetric encryption algorithm that uses a pair of mathematically linked keys. The public key encrypts data, and only the corresponding private key can decrypt it. This tool uses RSA-OAEP (Optimal Asymmetric Encryption Padding), which is the recommended padding scheme for new applications because it provides provable security against chosen-ciphertext attacks.
What is the maximum data size I can encrypt with RSA?
RSA can only encrypt data smaller than the key size minus the padding overhead. For RSA-OAEP with SHA-256 and a 2048-bit key, the maximum plaintext is 190 bytes (256 - 66). For a 4096-bit key, it is 446 bytes. If you need to encrypt larger data, use RSA to encrypt a symmetric key (hybrid encryption) — this is how TLS/SSL works.
Which hash algorithm should I choose?
Use SHA-256 unless you have a specific reason to choose otherwise. It is the default for most RSA-OAEP implementations and provides a good balance of security and performance. SHA-384 and SHA-512 offer higher security margins but are slower and less commonly used. The hash must match the one used during key generation.
Can I use keys generated by other tools?
Yes, as long as the keys are in PEM format (PKCS#8 for private keys, SPKI/X.509 for public keys) and use the RSA-OAEP algorithm. Keys generated by OpenSSL, the RSA Key Generator on this site, or most standard cryptographic libraries will work. Note that RSA-PKCS#1 v1.5 keys need to be re-generated as RSA-OAEP keys.
What if my data is larger than the RSA capacity?
Use hybrid encryption: generate a random AES-256 key, encrypt your data with AES, then encrypt only the AES key with RSA. This is how TLS/SSL works — RSA protects the symmetric key, and AES handles the bulk data efficiently.
Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.
More in Encryption
AES Encrypt/Decrypt
Encrypt and decrypt with AES-128/192/256 online. GCM, CTR, and OpenSSL-compatible CBC modes. Passphrase or raw key, custom IV.
ChaCha20 / Salsa20 Encrypt/Decrypt
Encrypt and decrypt with ChaCha20, XChaCha20, ChaCha20-Poly1305 (AEAD), or Salsa20 online. Passphrase mode with PBKDF2 key derivation.
DES Encrypt/Decrypt
Encrypt and decrypt with DES or 3DES (Triple DES) online. CBC/ECB/CFB/OFB modes, PKCS7/NoPadding, OpenSSL compatible.
XOR Encrypt/Decrypt
Encrypt and decrypt with XOR cipher online. Text/Hex/Base64 formats, visual XOR table, brute-force key breaking, auto-solve.
JWE Encrypt / Decrypt
Encrypt and decrypt JWE (JSON Web Encryption) tokens online. RSA-OAEP, AES key wrap, PBES2 password-based key management, A128GCM/A256GCM.
Blowfish Encrypt/Decrypt
Encrypt and decrypt with Blowfish online. 5 cipher modes, 5 paddings, GBK/UTF-16 support, OpenSSL passphrase compatible.
PGP Encrypt / Decrypt
Encrypt, decrypt, sign, and verify with OpenPGP online. Public key and password modes, built-in key generator, GnuPG compatible.