/// <summary> /// Generates a signature using the specified signatureType /// </summary> /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param> /// <param name="consumerKey">The consumer key</param> /// <param name="consumerSecret">The consumer seceret</param> /// <param name="token">The token, if available. If not available pass null or an empty string</param> /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param> /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param> /// <param name="signatureType">The type of signature to use</param> /// <returns>A base64 string of the hash value</returns> public static string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType) { switch (signatureType) { case SignatureTypes.PLAINTEXT: return(HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret))); case SignatureTypes.HMACSHA1: string signatureBase = GenerateSignatureBase( url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType); HMACSHA1 hmacsha1 = new HMACSHA1(); hmacsha1.Key = Util.Utilities.GetBytesFromAsciiString(GenerateOAuthSignature(consumerSecret, tokenSecret)); return(GenerateSignatureUsingHash(signatureBase, hmacsha1)); case SignatureTypes.RSASHA1: throw new NotImplementedException(); default: throw new ArgumentException("Unknown signature type", "signatureType"); } }
/// <summary> /// used as a cover method to hide the actual decoding implementation /// decodes an URL decoded string /// </summary> /// <param name="value">the string to decode</param> public static string UrlDecodedValue(string value) { return(HttpUtility.UrlDecode(value)); }