Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

Error while encrypt with RSA #226

Open
aBuder opened this issue Mar 31, 2020 · 1 comment
Open

Error while encrypt with RSA #226

aBuder opened this issue Mar 31, 2020 · 1 comment

Comments

@aBuder
Copy link

aBuder commented Mar 31, 2020

If I encrypt data with RSA key. The Data itself is also an RSA key with same length in XML format

VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: Invalid argument(s): Input too large for RSA cipher
```
@hoylen
Copy link
Contributor

hoylen commented May 21, 2020

RSA encryption only works on blocks that are smaller or equal to the key size.

If you want to use the RSA algorithm to directly encrypt data, you'll have to break up the plaintext into suitably sized blocks. There are some standard methods for doing this (such as RSAES-PKCS1-v1_5 and RSAES-OAEP) which are supported by Pointy Castle. See the "RSA encryption and decryption" section of the tutorial at https://github.com/PointyCastle/pointycastle/blob/master/tutorials/rsa.md. Though RSAES-PKCS1-v1_5 is not considered very secure these days, and is only there for backward compatibility. But directly encrypting data using RSA is not recommended.

The normal practice is to generate a random session key and encrypt the data using a symmetric algorithm (e.g. AES-256) and then encrypt the small session key using RSA. The receiver will use their private key and the RSA algorithm to decrypt the session key, and then use the decrypted session key to decrypt the data. This greatly improves performance, since the bulk data is encrypted/decrypted using the much faster symmetric algorithm rather than the slower RSA algorithm.

P.S. The Pointy Castle project has moved over to https://github.com/bcgit/pc-dart

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants