예제 #1
0
        /// <summary>
        /// add authorization
        /// </summary>
        /// <param name="qcloudSignSource">QCloudSignSource</param>
        /// <param name="request"></param>
        private void CheckSign(QCloudSignSource qcloudSignSource, Request request)
        {
            // has authorizaiton, notice: using request.Headers, otherwise, error
            if (request.Headers.ContainsKey(CosRequestHeaderKey.AUTHORIZAIION))
            {
                QLog.D(TAG, "has add authorizaiton in headers");
                return;
            }

            //has no authorization, but signSourceProvider == null
            if (qcloudSignSource == null)
            {
                QLog.D(TAG, "signSourceProvider == null");
                return;
            }

            if (credentialsProvider == null)
            {
                throw new ArgumentNullException("credentialsProvider == null");
            }

            CosXmlSigner signer = new CosXmlSigner();

            signer.Sign(request, qcloudSignSource, credentialsProvider.GetQCloudCredentials());
        }
예제 #2
0
 public string GenerateSign(string method, string key, Dictionary <string, string> queryParameters, Dictionary <string, string> headers, long signDurationSecond)
 {
     try
     {
         string signTime = null;
         if (signDurationSecond > 0)
         {
             long currentTimeSecond = TimeUtils.GetCurrentTime(TimeUnit.SECONDS);
             signTime = String.Format("{0};{1}", currentTimeSecond, currentTimeSecond + signDurationSecond);
         }
         Dictionary <string, string> encodeQuery = null;
         if (queryParameters != null)
         {
             encodeQuery = new Dictionary <string, string>(queryParameters.Count);
             foreach (KeyValuePair <string, string> keyValuePair in queryParameters)
             {
                 encodeQuery[keyValuePair.Key] = URLEncodeUtils.Encode(keyValuePair.Value);
             }
         }
         return(CosXmlSigner.GenerateSign(method, key, encodeQuery, headers, signTime, qcloudCredentailProvider.GetQCloudCredentials()));
     }
     catch (CosClientException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, ex.Message, ex);
     }
 }
예제 #3
0
        public string GenerateSign(string method, string key, Dictionary <string, string> queryParameters, Dictionary <string, string> headers, long signDurationSecond)
        {
            try
            {
                string signTime = null;

                if (signDurationSecond > 0)
                {
                    long currentTimeSecond = TimeUtils.GetCurrentTime(TimeUnit.Seconds);

                    signTime = String.Format("{0};{1}", currentTimeSecond, currentTimeSecond + signDurationSecond);
                }

                Dictionary <string, string> encodeQuery = null;

                if (queryParameters != null)
                {
                    encodeQuery = new Dictionary <string, string>(queryParameters.Count);

                    foreach (KeyValuePair <string, string> keyValuePair in queryParameters)
                    {
                        if (keyValuePair.Key == null || keyValuePair.Key == "")
                        {
                            continue;
                        }
                        else if (keyValuePair.Value == null)
                        {
                            encodeQuery[URLEncodeUtils.Encode(keyValuePair.Key).ToLower()] = URLEncodeUtils.Encode("");
                        }
                        else
                        {
                            encodeQuery[URLEncodeUtils.Encode(keyValuePair.Key).ToLower()] = URLEncodeUtils.Encode(keyValuePair.Value);
                        }
                    }
                }

                return(CosXmlSigner.GenerateSign(method, key, encodeQuery, headers, signTime, credentialProvider.GetQCloudCredentialsCompat(null)));
            }
            catch (CosClientException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new CosClientException((int)CosClientError.InvalidArgument, ex.Message, ex);
            }
        }