I have public and private key information from a self-signed certificate. I 
extract the RSA parameters using Microsoft cypto and then pass it to the code 
in the following function:

byte[] retValue = null;
            byte[] encrypted = null;

            IAsymmetricBlockCipher cipher = new Pkcs1Encoding(new RsaEngine());

            BigInteger modI = new BigInteger(1, rsaPubParmsMicrosoft.Modulus);
            BigInteger expI = new BigInteger(rsaPubParmsMicrosoft.Exponent);
            RsaKeyParameters rsaPublic = new RsaKeyParameters(false, modI, 
expI);

            modI = new BigInteger(1, rsaPrivateParmMicrosoft.Modulus);
            expI = new BigInteger(rsaPrivateParmMicrosoft.Exponent);
            RsaKeyParameters rsaPrivate = new RsaKeyParameters(true, modI, 
expI);
            byte[] data = { 0x01, 0x02, 0x03 };

            cipher.Init(true, rsaPrivate);
            try
            {
               encrypted = cipher.ProcessBlock(data, 0, data.Length);
            }
            catch(Exception ex)
            {
                string emsg = ex.ToString();
            }

            IAsymmetricBlockCipher cipher1 = new Pkcs1Encoding(new RsaEngine());
            cipher1.Init(false, rsaPublic);
            try
            {
                int blockLength = cipher1.GetInputBlockSize();
                retValue = cipher.ProcessBlock(encrypted, 0, blockLength);
            }
            catch(Exception ex)
            {
                string emsg = ex.ToString();
            }

The encryption works, however the decrypt throws the exception {"input data too 
large (Parameter 'inLen')"}.  The blocksize is: 0x00000100 And the size of 
encrypted is: {byte[0x00000100]}

Any ideas about why the exception is being thrown

Reply via email to