private HttpWebRequest PreparePostRequest <T>(String controller, String action, String parameters, T value, out byte[] byteData) where T : APIBaseRequest
        {
            APICompIDRequest wrapper;

            SignBytes signFunction = Interlocked.CompareExchange(ref signFunc, null, null);

            if (signFunction != null)
            {
                wrapper = new APISignedRequest(CompId)
                {
                    Request = value, Signature = signFunction(SerializingHelper.GetRequestBytes(value))
                }
            }
            ;
            else
            {
                wrapper = new APIPasswordRequest(CompId)
                {
                    Request = value, Password = (this.password ?? String.Empty)
                }
            };

            byteData = SerializingHelper.GetRequestBytes(wrapper);
            var request = GetApiRequest(controller, action, parameters);

            request.ContentType = "application/xml;charset=utf-16";
            request.Method      = "POST";
            //using (var stream = request.GetRequestStream())
            //{
            //    stream.Write(byteData, 0, byteData.Length);
            //}
            return(request);
        }
Exemple #2
0
        public static bool ValidateDSASignature(APIBaseRequest value, byte[] signature, byte[] publicKey)
        {
            DSAParameters algParams;

            using (MemoryStream mstr = new MemoryStream(publicKey))
            {
                BinaryFormatter fmt = new BinaryFormatter();
                try { algParams = (DSAParameters)fmt.Deserialize(mstr); }
                catch (SerializationException) { return(false); }
            }
            using (var provider = new DSACryptoServiceProvider())
            {
                try { provider.ImportParameters(algParams); }
                catch (CryptographicException) { return(false); }
                return(provider.VerifyData(SerializingHelper.GetRequestBytes(value), signature));
            }
        }