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)); }
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 result; 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); result = bigInteger3.Multiply(val).Mod(modulus); } else { result = core.ProcessBlock(bigInteger); } } else { result = core.ProcessBlock(bigInteger); } return(core.ConvertOutput(result)); }
/** * Process a single block using the basic RSA algorithm. * * @param inBuf the input array. * @param inOff the offset into the input buffer where the data starts. * @param inLen the length of the data to be processed. * @return the result of the RSA process. * @exception DataLengthException the input block is too large. */ public byte[] ProcessBlock( byte[] inBuf, int inOff, int inLen) { if (key == null) { throw new InvalidOperationException("RSA engine not initialised"); } BigInteger input = core.ConvertInput(inBuf, inOff, inLen); BigInteger result; if (key is RsaPrivateCrtKeyParameters) { RsaPrivateCrtKeyParameters k = (RsaPrivateCrtKeyParameters)key; BigInteger m = k.Modulus; BigInteger r = calculateR(m); BigInteger blindedInput = r.ModPow(k.PublicExponent, m).Multiply(input).Mod(m); BigInteger blindedResult = core.ProcessBlock(blindedInput); result = blindedResult.Multiply(r.ModInverse(m)).Mod(m); } else { result = core.ProcessBlock(input); } return(core.ConvertOutput(result)); }
public virtual byte[] ProcessBlock(byte[] inBuf, int inOff, int inLen) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (core == null) { throw new InvalidOperationException("RSA engine not initialised"); } return(core.ConvertOutput(core.ProcessBlock(core.ConvertInput(inBuf, inOff, inLen)))); }
/** * Process a single block using the basic RSA algorithm. * * @param inBuf the input array. * @param inOff the offset into the input buffer where the data starts. * @param inLen the length of the data to be processed. * @return the result of the RSA process. * @exception DataLengthException the input block is too large. */ public 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)))); }
/** * Process a single block using the basic RSA algorithm. * * @param inBuf the input array. * @param inOff the offset into the input buffer where the data starts. * @param inLen the length of the data to be processed. * @return the result of the RSA process. * @exception DataLengthException the input block is too large. */ public virtual byte[] ProcessBlock( byte[] inBuf, int inOff, int inLen) { if (key == null) { throw new InvalidOperationException("RSA engine not initialised"); } BigInteger input = core.ConvertInput(inBuf, inOff, inLen); BigInteger result; if (key is RsaPrivateCrtKeyParameters) { RsaPrivateCrtKeyParameters k = (RsaPrivateCrtKeyParameters)key; BigInteger e = k.PublicExponent; if (e != null) // can't do blinding without a public exponent { BigInteger m = k.Modulus; BigInteger r = BigIntegers.CreateRandomInRange( BigInteger.One, m.Subtract(BigInteger.One), random); BigInteger blindedInput = r.ModPow(e, m).Multiply(input).Mod(m); BigInteger blindedResult = core.ProcessBlock(blindedInput); BigInteger rInv = r.ModInverse(m); result = blindedResult.Multiply(rInv).Mod(m); // defence against Arjen Lenstra�s CRT attack if (!input.Equals(result.ModPow(e, m))) { throw new InvalidOperationException("RSA engine faulty decryption/signing detected"); } } else { result = core.ProcessBlock(input); } } else { result = core.ProcessBlock(input); } return(core.ConvertOutput(result)); }
/** * Process a single block using the RSA blinding algorithm. * * @param in the input array. * @param inOff the offset into the input buffer where the data starts. * @param inLen the length of the data to be processed. * @return the result of the RSA process. * @throws DataLengthException the input block is too large. */ public byte[] ProcessBlock( byte[] inBuf, int inOff, int inLen) { BigInteger msg = core.ConvertInput(inBuf, inOff, inLen); if (forEncryption) { msg = BlindMessage(msg); } else { msg = UnblindMessage(msg); } return(core.ConvertOutput(msg)); }
/** * Process a single block using the basic RSA algorithm. * * @param inBuf the input array. * @param inOff the offset into the input buffer where the data starts. * @param inLen the length of the data to be processed. * @return the result of the RSA process. * @exception DataLengthException the input block is too large. */ public byte[] ProcessBlock( byte[] inBuf, int inOff, int inLen) { if (key == null) { throw new InvalidOperationException("RSA engine not initialised"); } IBigInteger input = core.ConvertInput(inBuf, inOff, inLen); IBigInteger result; if (key is RsaPrivateCrtKeyParameters) { RsaPrivateCrtKeyParameters k = (RsaPrivateCrtKeyParameters)key; IBigInteger e = k.PublicExponent; if (e != null) // can't do blinding without a public exponent { IBigInteger m = k.Modulus; IBigInteger r = BigIntegers.CreateRandomInRange( BigInteger.One, m.Subtract(BigInteger.One), random); IBigInteger blindedInput = r.ModPow(e, m).Multiply(input).Mod(m); IBigInteger blindedResult = core.ProcessBlock(blindedInput); IBigInteger rInv = r.ModInverse(m); result = blindedResult.Multiply(rInv).Mod(m); } else { result = core.ProcessBlock(input); } } else { result = core.ProcessBlock(input); } return(core.ConvertOutput(result)); }
public virtual byte[] ProcessBlock(byte[] inBuf, int inOff, int inLen) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) 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)); }