Ejemplo n.º 1
0
        /// <summary>
        /// Creates a signature value given a signature base and the consumer secret and a known token secret.
        /// </summary>
        /// <a href="http://oauth.net/core/1.0#rfc.section.9.2"/>
        /// <param name="signatureProvider">The hashing method</param>
        /// <param name="signatureTreatment">The treatment to use on a signature value</param>
        /// <param name="signatureBase">The signature base</param>
        /// <param name="consumerSecret">The consumer secret</param>
        /// <param name="tokenSecret">The token secret</param>
        /// <returns></returns>
        public static string GetSignature(
            ISignatureProvider signatureProvider,
            OAuthSignatureTreatment signatureTreatment,
            string signatureBase,
            string consumerSecret,
            string tokenSecret)
        {
            if (string.IsNullOrEmpty(tokenSecret))
            {
                tokenSecret = string.Empty;
            }
            consumerSecret = UrlEncodeRelaxed(consumerSecret);
            tokenSecret    = UrlEncodeRelaxed(tokenSecret);
            var data      = _encoding.GetBytes(signatureBase);
            var hash      = signatureProvider.CalculateSignature(data, consumerSecret, tokenSecret);
            var signature = hash;

            var result = signatureTreatment == OAuthSignatureTreatment.Escaped
                             ? UrlEncodeRelaxed(signature)
                             : signature;

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a signature value given a signature base and the consumer secret and a known token secret.
        /// </summary>
        /// <a href="http://oauth.net/core/1.0#rfc.section.9.2"/>
        /// <param name="signatureProvider">The hashing method</param>
        /// <param name="signatureTreatment">The treatment to use on a signature value</param>
        /// <param name="signatureBase">The signature base</param>
        /// <param name="consumerSecret">The consumer secret</param>
        /// <param name="tokenSecret">The token secret</param>
        /// <returns></returns>
        public static string GetSignature(
            ISignatureProvider signatureProvider,
            OAuthSignatureTreatment signatureTreatment,
            string signatureBase,
            string consumerSecret,
            string tokenSecret)
        {
            if (string.IsNullOrEmpty(tokenSecret))
            {
                tokenSecret = string.Empty;
            }
            consumerSecret = UrlEncodeRelaxed(consumerSecret);
            tokenSecret = UrlEncodeRelaxed(tokenSecret);
            var data = _encoding.GetBytes(signatureBase);
            var hash = signatureProvider.CalculateSignature(data, consumerSecret, tokenSecret);
            var signature = hash;

            var result = signatureTreatment == OAuthSignatureTreatment.Escaped
                             ? UrlEncodeRelaxed(signature)
                             : signature;
            return result;
        }