Example #1
0
        private byte[] pkcs1unpad2(BigInteger m, int b)
        {
            byte[] bytes = m.getBytes();

            int i = 0;
            while (i < bytes.Length && bytes[i] == 0) ++i;

            if (bytes.Length - i != (b - 1) || bytes[i] != 0x2)
            {
                return null;
            }

            while (bytes[i] != 0)
            {
                if (++i >= bytes.Length)
                {
                    return null;
                }
            }

            byte[] result = new byte[bytes.Length - i + 1];
            int p = 0;
            while (++i < bytes.Length)
            {
                result[p++] = bytes[i];
            }

            return result;
        }