示例#1
0
        public static bool Decrypt(ref byte[] buffer, int position, int length)
        {
            if (length - position != 128)
                return false;

            byte[] temp = new byte[128];
            Array.Copy(buffer, position, temp, 0, 128);

            BigInteger input = new BigInteger(temp);
            BigInteger output;

            BigInteger m1 = input.modPow(otServerDP, otServerP);
            BigInteger m2 = input.modPow(otServerDQ, otServerQ);
            BigInteger h;

            if (m2 > m1)
            {
                h = otServerP - ((m2 - m1) * otServerInverseQ % otServerP);
                output = m2 + otServerQ * h;
            }
            else
            {

                h = (m1 - m2) * otServerInverseQ % otServerP;

                output = m2 + otServerQ * h;
            }

            Array.Copy(GetPaddedValue(output), 0, buffer, position, 128);
            return true;
        }
示例#2
0
        public static bool Encrypt(BigInteger e, BigInteger m, ref byte[] buffer, int position)
        {
            byte[] temp = new byte[128];

            Array.Copy(buffer, position, temp, 0, 128);

            BigInteger input = new BigInteger(temp);
            BigInteger output = input.modPow(e, m);

            Array.Copy(GetPaddedValue(output), 0, buffer, position, 128);

            return true;
        }