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));
    }
Ejemplo 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))));
 }
Ejemplo n.º 3
0
 public byte[] Sign(byte[] data, out uint160 nonce)
 {
     while (true)
     {
         byte[] output = new byte[256];
         nonce = new uint160(RandomUtils.GetBytes(20));
         Sha512Digest sha512    = new Sha512Digest();
         var          msg       = Utils.Combine(nonce.ToBytes(), data);
         var          generator = new Mgf1BytesGenerator(sha512);
         generator.Init(new MgfParameters(msg));
         generator.GenerateBytes(output, 0, output.Length);
         var input = new BigInteger(1, output);
         if (input.CompareTo(_Key.Modulus) >= 0)
         {
             continue;
         }
         var engine = new RsaCoreEngine();
         engine.Init(true, _Key);
         return(engine.ConvertOutput(engine.ProcessBlock(input)));
     }
 }
    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));
    }