Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Decrypt RSA encrypted Key

Long story short, I'm using DES and I'm encrypting a password using RSA for key exchange, the password does not exceed 16 characters the problem is when i encrypt the key, the encrypted size becomes too big for me to decrypt here's my rsa encrypt and decrypt code:

Encrypt:--i've been trying the localpwd as "asd"

    byte[] plaintext = utf8.GetBytes(localpwd);
    byte[] ciphertext = rsaservice.Encrypt(plaintext, false);
    string cipherresult = Convert.ToBase64String(ciphertext);

then i print the encrypted key on the textbox and try decrypting

    byte[] ciphertext = utf8.GetBytes(filetest.Text);
    byte[] plain = rsaservice.Decrypt(ciphertext, true);
    string plaintext = utf8.GetString(plain);

i get "the data to be decrypted exceeds the maximum for this modulus of 256 bytes". i tried increasing the key size to be able to encrypt and decrypt larger key sizes, but increasing the key just increases the size of the encrypted data resulting in the same error please help!!!

like image 284
Adel Ahmed Avatar asked Feb 17 '26 16:02

Adel Ahmed


1 Answers

//byte[] ciphertext = utf8.GetBytes(filetest.Text);
  byte[] ciphertext = Convert.FromBase64String(filetest.Text);
like image 111
Henk Holterman Avatar answered Feb 19 '26 04:02

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!