示例#1
0
        public string Decode(string cipherText)
        {
            int cipherTextLength = cipherText.Length;

            if (cipherTextLength != PrivateKey.getK())
            {
                throw new ArgumentException("Decription error");
            }

            BigInteger c = OS2IP(cipherText);

            c = PowModul(c, PrivateKey.getD(), PrivateKey.GetN());
            string message = I2OSP(c, PrivateKey.getK());

            if (message[0] != '0' || message[1] != '2')
            {
                throw new DecryptionErrorExecption("First two bytes is wrong");
            }
            int messageLength = message.Length;
            int count         = 2;

            while (count < messageLength)
            {
                if (message[count] == '0')
                {
                    if (count < 10)
                    {
                        throw new DecryptionErrorExecption("PS length is less 8");
                    }
                    return(message.Substring(count + 1));
                }
                count++;
            }

            throw new DecryptionErrorExecption("No zero byte");
        }