Practical Guide

RSA Encryption/Decryption โ€” Usage Guide and Technical Principles

Encrypt short UTF-8 text or decrypt Base64 ciphertext locally with RSA-OAEP and SHA-256. Load a sample key pair or use a matching SPKI public key and PKCS#8 private key in PEM format.

Open tool

Overview

RSA (Rivest-Shamir-Adleman) is an asymmetric encryption algorithm that uses public and private key pairs for data encryption and decryption. The public key encrypts data while the private key decrypts it, ensuring secure data transmission. RSA algorithm is based on the mathematical difficulty of large number factorization, widely used in digital signatures, SSL/TLS protocols, secure communication, and is a fundamental component of modern cryptography.

Key concepts

RSA Asymmetric Cryptography Fundamentals

RSA (Rivest-Shamir-Adleman) is a public-key cryptosystem using asymmetric encryption where different keys are used for encryption and decryption. The system relies on the mathematical difficulty of factoring large prime numbers. RSA uses a key pair: public key (e, n) for encryption and private key (d, n) for decryption. Encryption transforms plaintext M into ciphertext C using C = M^e mod n, while decryption recovers plaintext using M = C^d mod n.

Features

Encrypt

Encrypt short UTF-8 text or decrypt Base64 ciphertext locally with RSA-OAEP and SHA-256. Load a sample key pair or use a matching SPKI public key and PKCS#8 private key in PEM format.

Application Scenarios

Load Sample

Encrypt short UTF-8 text or decrypt Base64 ciphertext locally with RSA-OAEP and SHA-256. Load a sample key pair or use a matching SPKI public key and PKCS#8 private key in PEM format.

Frequently asked questions

What's the difference between RSA and AES encryption?

RSA is asymmetric encryption using public key to encrypt and private key to decrypt - highly secure but slow, suitable for encrypting keys and small amounts of data. AES is symmetric encryption using the same key for encryption and decryption - fast but key distribution is difficult, suitable for encrypting large amounts of data. In practice, hybrid encryption is commonly used: RSA encrypts the AES key, AES encrypts the actual data.

Why is encrypted data much longer than the original data?

RSA encryption pads the input data (like OAEP padding) and encodes the encrypted result in Base64 format for transmission. A 2048-bit RSA key outputs approximately 344 bytes after encryption (256 bytes ciphertext + Base64 encoding overhead), even if the original data is only a few bytes. This is normal behavior for the RSA algorithm.

What RSA key length should I choose?

2048 bits is the currently recommended minimum key length, meeting most security needs and expected to be secure until 2030. 3072 or 4096 bits provide higher security, suitable for long-term protection (20+ years) scenarios. Longer keys mean slower encryption/decryption speeds. 1024-bit keys are not recommended as they're considered insufficiently secure.

Can public and private keys be used interchangeably?

Mathematically, RSA public and private keys can be interchanged for encryption and decryption. However, in practice, public keys are used for encryption (anyone can encrypt data to send to you), and private keys for decryption (only you can decrypt). The scenario of encrypting with private key and decrypting with public key is called digital signature, used to verify data origin and integrity.

Why can't my private key decrypt data encrypted with someone else's public key?

RSA key pairs are generated in pairs - each public key can only be decrypted by its corresponding private key. If you encrypt data with person A's public key, only A's private key can decrypt it; your own private key cannot. Ensure encryption and decryption use the same key pair.

Is RSA encryption 100% secure?

No encryption algorithm is absolutely secure. RSA security is based on the mathematical difficulty of factoring large numbers and is currently considered secure. However, note: 1) Use sufficiently long keys (โ‰ฅ2048 bits); 2) Use correct padding schemes (OAEP); 3) Properly safeguard private keys; 4) Be aware of quantum computing threats (may break RSA in the future); 5) Regularly update keys.

Related Documents

RSA Encryption/Decryption

Open the tool to try these features.

Open tool