public virtual byte[] ProcessBlock(byte[] inBuf, int inOff, int inLen)
    {
        BigInteger bigInteger = core.ConvertInput(inBuf, inOff, inLen);

        bigInteger = ((!forEncryption) ? UnblindMessage(bigInteger) : BlindMessage(bigInteger));
        return(core.ConvertOutput(bigInteger));
    }
Esempio n. 2
0
 public virtual byte[] ProcessBlock(byte[] inBuf, int inOff, int inLen)
 {
     if (core == null)
     {
         throw new InvalidOperationException("RSA engine not initialised");
     }
     return(core.ConvertOutput(core.ProcessBlock(core.ConvertInput(inBuf, inOff, inLen))));
 }
    public virtual byte[] ProcessBlock(byte[] inBuf, int inOff, int inLen)
    {
        if (key == null)
        {
            throw new InvalidOperationException("RSA engine not initialised");
        }
        BigInteger bigInteger = core.ConvertInput(inBuf, inOff, inLen);
        BigInteger bigInteger4;

        if (key is RsaPrivateCrtKeyParameters)
        {
            RsaPrivateCrtKeyParameters rsaPrivateCrtKeyParameters = (RsaPrivateCrtKeyParameters)key;
            BigInteger publicExponent = rsaPrivateCrtKeyParameters.PublicExponent;
            if (publicExponent != null)
            {
                BigInteger modulus     = rsaPrivateCrtKeyParameters.Modulus;
                BigInteger bigInteger2 = BigIntegers.CreateRandomInRange(BigInteger.One, modulus.Subtract(BigInteger.One), random);
                BigInteger input       = bigInteger2.ModPow(publicExponent, modulus).Multiply(bigInteger).Mod(modulus);
                BigInteger bigInteger3 = core.ProcessBlock(input);
                BigInteger val         = bigInteger2.ModInverse(modulus);
                bigInteger4 = bigInteger3.Multiply(val).Mod(modulus);
                if (!bigInteger.Equals(bigInteger4.ModPow(publicExponent, modulus)))
                {
                    throw new InvalidOperationException("RSA engine faulty decryption/signing detected");
                }
            }
            else
            {
                bigInteger4 = core.ProcessBlock(bigInteger);
            }
        }
        else
        {
            bigInteger4 = core.ProcessBlock(bigInteger);
        }
        return(core.ConvertOutput(bigInteger4));
    }