RSACryptoServiceProvider - Decrypt

2

Using RSA encryption, I pass the encrypted data from the client to the server decrypt. When trying to decrypt, it gives me an exception CryptographicException with the message:

  

Invalid flags specified.

I have no idea Flag may be missing.

My code looks like this:

byte[] decryptedMessage;
RSACryptoServiceProvider asr = new RSACryptoServiceProvider(128);
decryptedMessage = asr.Decrypt(buffer, false);
  

at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException (Int32 hr)          in System.Security.Cryptography.Utils._GenerateKey (SafeProvHandle hProv, Int32 algid, CspProviderFlags flags, Int32 keySize, SafeKeyHandle & hKey)          in System.Security.Cryptography.Utils.GetKeyPairHelper (CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle & safeProvHandle, SafeKeyHandle & safeKeyHandle)          in System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair ()          in System.Security.Cryptography.RSACryptoServiceProvider.Decrypt (Byte [rgb, Boolean fOAEP]

    
asked by anonymous 17.06.2014 / 15:24

1 answer

0

RSACryptoServiceProvider does not support 128-bit keys:

  

The support key sizes of 384 bit RSACryptoServiceProvider to 16384 bits in 8-bit increments if you have the enhanced Microsoft Encryption Provider installed. Supports 384-bit to 512-bit key sizes in 8-bit increments if you have the Microsoft Base Cryptographic Provider installed.

Source: MSDN - Property RSACryptoServiceProvider.KeySize

Original SOen response .

    
18.06.2014 / 06:33