RSA Encryption/Decryption

Key Size

Algorithm

Mode

Public Key

Private Key

Plain Text

Encrypted Text

Note: This is a demo implementation for educational purposes only.

About RSA Encryption

RSA (Rivest-Shamir-Adleman) is a public-key cryptosystem widely used for secure data transmission. It relies on the mathematical difficulty of factoring large prime numbers. The algorithm generates a key pair consisting of a public key (used for encryption) and a private key (used for decryption). The security of RSA depends on the key size - larger keys (2048+ bits) provide stronger security but require more computational resources.

Padding schemes are crucial for RSA security and compatibility. PKCS#1 v1.5 padding is the traditional method, widely supported but vulnerable to certain attacks. OAEP (Optimal Asymmetric Encryption Padding) provides enhanced security by adding randomness and is recommended for new applications. The choice of padding affects both security and interoperability between different RSA implementations.

When using RSA encryption, the maximum message length is limited by the key size minus padding overhead. For example, a 2048-bit key with PKCS#1 padding can encrypt up to 245 bytes of data. Longer messages require hybrid encryption, where RSA encrypts a symmetric key that encrypts the actual data. Always use the same padding scheme and key format for encryption and decryption to ensure compatibility.