Cannot Decrypt RSA encrypted Key

2019-02-25 05:51发布

问题:

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!!!

回答1:

//byte[] ciphertext = utf8.GetBytes(filetest.Text);
  byte[] ciphertext = Convert.FromBase64String(filetest.Text);