Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input too large for RSA cipher #4

Open
chandaniBhalala opened this issue Sep 29, 2020 · 1 comment
Open

Input too large for RSA cipher #4

chandaniBhalala opened this issue Sep 29, 2020 · 1 comment
Assignees
Labels
help wanted Extra attention is needed

Comments

@chandaniBhalala
Copy link

chandaniBhalala commented Sep 29, 2020

Getting this exception "Input too large for RSA cipher" when encrypting string with more than 64 characters.
Is there any limit of number of characters for encryption?

flutter doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-IN)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.49.2)
[✓] Connected device (3 available)

@nullptr-31 nullptr-31 added the help wanted Extra attention is needed label Sep 29, 2020
@nullptr-31 nullptr-31 self-assigned this Sep 29, 2020
@mnesarco
Copy link

RSA can only encrypt payloads smaller than the key size, so the usual way to use that is:

Given a payload P and a public key PK:

  1. Generate a random key K
  2. Encrypt the payload P with symmetric encryption (ie AES) using the generated key: EP = AESEncrypt( P, K )
  3. Encrypt the key K with RSA and public key PK: EK = RSAEncrypt( K, PK )
  4. Build a package PKG with encrypted key, encrypted payload and size: PKG = { EK, EP, size_of(P) }

Then to decrypt do the opposite:

Given a package PKG and a private key PRIVK:

  1. Extract parts from package: { EK, EP, SIZE } = PKG
  2. Decrypt the key K from EK with RSA and private key: K = RSADecrypt( EK, PRIVK )
  3. Decrypt the payload P using the key K and symmetric encryption: P = AESDecrypt( EP, K )
  4. Remove Padding: P = Trim_To( P, SIZE )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants