RSA-OAEP Encrypt & Decrypt Online | PEM PKCS#8 Public Key

Encryption
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.
⚠️ Critical Security: Never use RSA-PKCS#1 v1.5 for encryption — it's vulnerable to Bleichenbacher padding oracle attacks. Always use RSA-OAEP. Use at least 2048-bit keys (3072+ recommended for long-term security).

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 SizeMax PlaintextSecurity LevelRecommended
RSA-2048190 bytes112-bitMinimum acceptable
RSA-3072318 bytes128-bitRecommended for most use
RSA-4096446 bytes152-bitHigh-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

⚠️ Using RSA-PKCS#1 v1.5 for Encryption — PKCS#1 v1.5 is vulnerable to Bleichenbacher padding oracle attacks. Always use RSA-OAEP for new applications.
⚠️ Insufficient Key Size — RSA keys smaller than 2048 bits are considered insecure. NIST recommends at least 2048-bit keys; use 3072+ for long-term security.
⚠️ Hash Mismatch — The OAEP hash algorithm must be identical between key generation and encryption/decryption. A mismatch will cause decryption to fail.
⚠️ Encrypting Large Data Directly — RSA can only encrypt data smaller than key size minus padding (190 bytes for RSA-2048 with SHA-256). For larger data, use hybrid encryption: RSA wraps an AES key, AES encrypts the data.
⚠️ Reusing RSA Keys for Multiple Purposes — Don't use the same RSA key pair for both encryption and signing. Generate separate keys for each purpose to prevent cross-protocol attacks.

Security Notes

🔒 RSA-OAEP only — never use PKCS#1 v1.5 for encryption; it is vulnerable to padding oracle attacks (Bleichenbacher).
🔒 Hybrid encryption for large data — RSA can only encrypt data smaller than key size minus padding; use RSA to wrap an AES key for bulk data.
🔒 Hash must match — the OAEP hash algorithm must be identical between key generation and encryption/decryption.
🔒 Key size ≥ 2048 bits — NIST recommends at least 2048-bit RSA; 3072+ for long-term security.

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

Related Concepts

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

Learn More