Check to see if one of the items is zero prefixed.  Msft requires that all
of the parameters be of the correct length but other libraries want to have
unsigned numbers, thus the zero prefix.

 

From: Herbert Falk <herb.f...@otb-consultingservices.com> 
Sent: Saturday, September 5, 2020 12:30 PM
To: dev-crypto-csharp@bouncycastle.org
Subject: [dev-crypto-csharp] Problems with the RSA decrypt: input data too
large

 

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