473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What is wrong with this namespace

I am keep having the "No overload for method 'GenerateSignature' takes 9 arguments" problem. Can you please tell me what is wrong with this class.
This code is the sample from the Oauth.net . I think it too old for my asp.net 3.5 or 4.0.

My page.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" AutoEventWireup="true"%>
  3. <%@ Import Namespace="OAuth" %>
  4. <%@ Import Namespace="System" %>
  5. <%@ Import Namespace="System.Net" %>
  6. <%@ Import Namespace="System.IO" %>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8.  
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head runat="server">
  11.     <title></title>
  12. </head>
  13. <body>
  14.     <form id="form1" runat="server">
  15.     <div>
  16.     <%
  17. OAuthBase oauth = new OAuthBase();
  18. Uri url = new Uri("http://ssdsdafdasfdsafdsa.example.net/photos?file=vacation.jpg&size=original");
  19. string signature = oauth.GenerateSignature(url,"dpf43f3p2l4k3l03", "kd94hf93k423kf44", "nnch734d00sl2jdk", "pfkkdhi9sl3r4s00", "GET", oauth.GenerateTimeStamp(), oauth.GenerateNonce(), OAuthBase.SignatureTypes.HMACSHA1);
  20.          %>
  21.     </div>
  22.     </form>
  23. </body>
  24. </html>
  25.  
  26.  

this code is from the Oauth.net website for generating the signature.
Expand|Select|Wrap|Line Numbers
  1.  
  2. //THE APP_CODE
  3. using System;
  4. using System.Security.Cryptography;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using System.Web;
  8.  
  9. namespace OAuth {
  10.     public class OAuthBase {
  11.         /// <summary>
  12.         /// Provides a predefined set of algorithms that are supported officially by the protocol
  13.         /// </summary>
  14.         public enum SignatureTypes {
  15.             HMACSHA1,
  16.             PLAINTEXT,
  17.             RSASHA1
  18.         }
  19.  
  20.         /// <summary>
  21.         /// Provides an internal structure to sort the query parameter
  22.         /// </summary>
  23.         protected class QueryParameter {
  24.             private string name = null;
  25.             private string value = null;
  26.  
  27.             public QueryParameter(string name, string value) {
  28.                 this.name = name;
  29.                 this.value = value;
  30.             }
  31.  
  32.             public string Name {
  33.                 get { return name; }
  34.             }
  35.  
  36.             public string Value {
  37.                 get { return value; }
  38.             }            
  39.         }
  40.  
  41.         /// <summary>
  42.         /// Comparer class used to perform the sorting of the query parameters
  43.         /// </summary>
  44.         protected class QueryParameterComparer : IComparer<QueryParameter> {
  45.  
  46.             #region IComparer<QueryParameter> Members
  47.  
  48.             public int Compare(QueryParameter x, QueryParameter y) {
  49.                 if (x.Name == y.Name) {
  50.                     return string.Compare(x.Value, y.Value);
  51.                 } else {
  52.                     return string.Compare(x.Name, y.Name);
  53.                 }
  54.             }
  55.  
  56.             #endregion
  57.         }
  58.  
  59.         protected const string OAuthVersion = "1.0";
  60.         protected const string OAuthParameterPrefix = "oauth_";
  61.  
  62.         //
  63.         // List of know and used oauth parameters' names
  64.         //        
  65.         protected const string OAuthConsumerKeyKey = "oauth_consumer_key";
  66.         protected const string OAuthCallbackKey = "oauth_callback";
  67.         protected const string OAuthVersionKey = "oauth_version";
  68.         protected const string OAuthSignatureMethodKey = "oauth_signature_method";
  69.         protected const string OAuthSignatureKey = "oauth_signature";
  70.         protected const string OAuthTimestampKey = "oauth_timestamp";
  71.         protected const string OAuthNonceKey = "oauth_nonce";
  72.         protected const string OAuthTokenKey = "oauth_token";
  73.         protected const string OAuthTokenSecretKey = "oauth_token_secret";
  74.  
  75.         protected const string HMACSHA1SignatureType = "HMAC-SHA1";
  76.         protected const string PlainTextSignatureType = "PLAINTEXT";
  77.         protected const string RSASHA1SignatureType = "RSA-SHA1";
  78.  
  79.         protected Random random = new Random();
  80.  
  81.         protected string unreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";
  82.  
  83.         /// <summary>
  84.         /// Helper function to compute a hash value
  85.         /// </summary>
  86.         /// <param name="hashAlgorithm">The hashing algoirhtm used. If that algorithm needs some initialization, like HMAC and its derivatives, they should be initialized prior to passing it to this function</param>
  87.         /// <param name="data">The data to hash</param>
  88.         /// <returns>a Base64 string of the hash value</returns>
  89.         private string ComputeHash(HashAlgorithm hashAlgorithm, string data) {
  90.             if (hashAlgorithm == null) {
  91.                 throw new ArgumentNullException("hashAlgorithm");
  92.             }
  93.  
  94.             if (string.IsNullOrEmpty(data)) {
  95.                 throw new ArgumentNullException("data");
  96.             }
  97.  
  98.             byte[] dataBuffer = System.Text.Encoding.ASCII.GetBytes(data);
  99.             byte[] hashBytes = hashAlgorithm.ComputeHash(dataBuffer);
  100.  
  101.             return Convert.ToBase64String(hashBytes);
  102.         }
  103.  
  104.         /// <summary>
  105.         /// Internal function to cut out all non oauth query string parameters (all parameters not begining with "oauth_")
  106.         /// </summary>
  107.         /// <param name="parameters">The query string part of the Url</param>
  108.         /// <returns>A list of QueryParameter each containing the parameter name and value</returns>
  109.         private List<QueryParameter> GetQueryParameters(string parameters) {
  110.             if (parameters.StartsWith("?")) {
  111.                 parameters = parameters.Remove(0, 1);
  112.             }
  113.  
  114.             List<QueryParameter> result = new List<QueryParameter>();
  115.  
  116.             if (!string.IsNullOrEmpty(parameters)) {
  117.                 string[] p = parameters.Split('&');
  118.                 foreach (string s in p) {
  119.                     if (!string.IsNullOrEmpty(s) && !s.StartsWith(OAuthParameterPrefix)) {
  120.                         if (s.IndexOf('=') > -1) {
  121.                             string[] temp = s.Split('=');
  122.                             result.Add(new QueryParameter(temp[0], temp[1]));
  123.                         } else {
  124.                             result.Add(new QueryParameter(s, string.Empty));
  125.                         }
  126.                     }
  127.                 }
  128.             }
  129.  
  130.             return result;
  131.         }
  132.  
  133.         /// <summary>
  134.         /// This is a different Url Encode implementation since the default .NET one outputs the percent encoding in lower case.
  135.         /// While this is not a problem with the percent encoding spec, it is used in upper case throughout OAuth
  136.         /// </summary>
  137.         /// <param name="value">The value to Url encode</param>
  138.         /// <returns>Returns a Url encoded string</returns>
  139.         protected string UrlEncode(string value) {
  140.             StringBuilder result = new StringBuilder();
  141.  
  142.             foreach (char symbol in value) {
  143.                 if (unreservedChars.IndexOf(symbol) != -1) {
  144.                     result.Append(symbol);
  145.                 } else {
  146.                     result.Append('%' + String.Format("{0:X2}", (int)symbol));
  147.                 }
  148.             }
  149.  
  150.             return result.ToString();
  151.         }
  152.  
  153.         /// <summary>
  154.         /// Normalizes the request parameters according to the spec
  155.         /// </summary>
  156.         /// <param name="parameters">The list of parameters already sorted</param>
  157.         /// <returns>a string representing the normalized parameters</returns>
  158.         protected string NormalizeRequestParameters(IList<QueryParameter> parameters) {            
  159.             StringBuilder sb = new StringBuilder();
  160.             QueryParameter p = null;
  161.             for (int i = 0; i < parameters.Count; i++) {
  162.                 p = parameters[i];
  163.                 sb.AppendFormat("{0}={1}", p.Name, p.Value);
  164.  
  165.                 if (i < parameters.Count - 1) {
  166.                     sb.Append("&");
  167.                 }
  168.             }
  169.  
  170.             return sb.ToString();
  171.         }
  172.  
  173.         /// <summary>
  174.         /// Generate the signature base that is used to produce the signature
  175.         /// </summary>
  176.         /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
  177.         /// <param name="consumerKey">The consumer key</param>        
  178.         /// <param name="token">The token, if available. If not available pass null or an empty string</param>
  179.         /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
  180.         /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
  181.         /// <param name="signatureType">The signature type. To use the default values use <see cref="OAuthBase.SignatureTypes">OAuthBase.SignatureTypes</see>.</param>
  182.         /// <returns>The signature base</returns>
  183.         public string GenerateSignatureBase(Uri url, string consumerKey, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, string signatureType, out string normalizedUrl, out string normalizedRequestParameters) {
  184.             if (token == null) {
  185.                 token = string.Empty;
  186.             }
  187.  
  188.             if (tokenSecret == null) {
  189.                 tokenSecret = string.Empty;
  190.             }
  191.  
  192.             if (string.IsNullOrEmpty(consumerKey)) {
  193.                 throw new ArgumentNullException("consumerKey");
  194.             }
  195.  
  196.             if (string.IsNullOrEmpty(httpMethod)) {
  197.                 throw new ArgumentNullException("httpMethod");
  198.             }
  199.  
  200.             if (string.IsNullOrEmpty(signatureType)) {
  201.                 throw new ArgumentNullException("signatureType");
  202.             }
  203.  
  204.             normalizedUrl = null;
  205.             normalizedRequestParameters = null;
  206.  
  207.             List<QueryParameter> parameters = GetQueryParameters(url.Query);
  208.             parameters.Add(new QueryParameter(OAuthVersionKey, OAuthVersion));
  209.             parameters.Add(new QueryParameter(OAuthNonceKey, nonce));
  210.             parameters.Add(new QueryParameter(OAuthTimestampKey, timeStamp));
  211.             parameters.Add(new QueryParameter(OAuthSignatureMethodKey, signatureType));
  212.             parameters.Add(new QueryParameter(OAuthConsumerKeyKey, consumerKey));
  213.  
  214.             if (!string.IsNullOrEmpty(token)) {
  215.                 parameters.Add(new QueryParameter(OAuthTokenKey, token));
  216.             }
  217.  
  218.             parameters.Sort(new QueryParameterComparer());
  219.  
  220.             normalizedUrl = string.Format("{0}://{1}", url.Scheme, url.Host);
  221.             if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443)))
  222.             {
  223.                 normalizedUrl += ":" + url.Port;
  224.             }
  225.             normalizedUrl += url.AbsolutePath;
  226.             normalizedRequestParameters = NormalizeRequestParameters(parameters);
  227.  
  228.             StringBuilder signatureBase = new StringBuilder();            
  229.             signatureBase.AppendFormat("{0}&", httpMethod.ToUpper());
  230.             signatureBase.AppendFormat("{0}&", UrlEncode(normalizedUrl));
  231.             signatureBase.AppendFormat("{0}", UrlEncode(normalizedRequestParameters));
  232.  
  233.             return signatureBase.ToString();
  234.         }
  235.  
  236.         /// <summary>
  237.         /// Generate the signature value based on the given signature base and hash algorithm
  238.         /// </summary>
  239.         /// <param name="signatureBase">The signature based as produced by the GenerateSignatureBase method or by any other means</param>
  240.         /// <param name="hash">The hash algorithm used to perform the hashing. If the hashing algorithm requires initialization or a key it should be set prior to calling this method</param>
  241.         /// <returns>A base64 string of the hash value</returns>
  242.         public string GenerateSignatureUsingHash(string signatureBase, HashAlgorithm hash) {
  243.             return ComputeHash(hash, signatureBase);
  244.         }
  245.  
  246.         /// <summary>
  247.         /// Generates a signature using the HMAC-SHA1 algorithm
  248.         /// </summary>        
  249.         /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
  250.         /// <param name="consumerKey">The consumer key</param>
  251.         /// <param name="consumerSecret">The consumer seceret</param>
  252.         /// <param name="token">The token, if available. If not available pass null or an empty string</param>
  253.         /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
  254.         /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
  255.         /// <returns>A base64 string of the hash value</returns>
  256.         public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, out string normalizedUrl, out string normalizedRequestParameters) {            
  257.             return GenerateSignature(url, consumerKey, consumerSecret, token, tokenSecret, httpMethod, timeStamp, nonce, SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);
  258.         }
  259.  
  260.         /// <summary>
  261.         /// Generates a signature using the specified signatureType 
  262.         /// </summary>        
  263.         /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
  264.         /// <param name="consumerKey">The consumer key</param>
  265.         /// <param name="consumerSecret">The consumer seceret</param>
  266.         /// <param name="token">The token, if available. If not available pass null or an empty string</param>
  267.         /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty string</param>
  268.         /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
  269.         /// <param name="signatureType">The type of signature to use</param>
  270.         /// <returns>A base64 string of the hash value</returns>
  271.         public string GenerateSignature(Uri url, string consumerKey, string consumerSecret, string token, string tokenSecret, string httpMethod, string timeStamp, string nonce, SignatureTypes signatureType, out string normalizedUrl, out string normalizedRequestParameters) {
  272.             normalizedUrl = null;
  273.             normalizedRequestParameters = null;
  274.  
  275.             switch (signatureType) {
  276.                 case SignatureTypes.PLAINTEXT:                    
  277.                     return HttpUtility.UrlEncode(string.Format("{0}&{1}", consumerSecret, tokenSecret));
  278.                 case SignatureTypes.HMACSHA1:                    
  279.                     string signatureBase = GenerateSignatureBase(url, consumerKey, token, tokenSecret, httpMethod, timeStamp, nonce, HMACSHA1SignatureType, out normalizedUrl, out normalizedRequestParameters);
  280.  
  281.                     HMACSHA1 hmacsha1 = new HMACSHA1();
  282.                     hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(consumerSecret), string.IsNullOrEmpty(tokenSecret) ? "" : UrlEncode(tokenSecret)));
  283.  
  284.                     return GenerateSignatureUsingHash(signatureBase, hmacsha1);                                        
  285.                 case SignatureTypes.RSASHA1:
  286.                     throw new NotImplementedException();
  287.                 default:
  288.                     throw new ArgumentException("Unknown signature type", "signatureType");
  289.             }
  290.         }
  291.  
  292.         /// <summary>
  293.         /// Generate the timestamp for the signature        
  294.         /// </summary>
  295.         /// <returns></returns>
  296.         public virtual string GenerateTimeStamp() {
  297.             // Default implementation of UNIX time of the current UTC time
  298.             TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  299.             return Convert.ToInt64(ts.TotalSeconds).ToString();            
  300.         }
  301.  
  302.         /// <summary>
  303.         /// Generate a nonce
  304.         /// </summary>
  305.         /// <returns></returns>
  306.         public virtual string GenerateNonce() {
  307.             // Just a simple implementation of a random number between 123400 and 9999999
  308.             return random.Next(123400, 9999999).ToString();            
  309.         }
  310.  
  311.     }
  312. }
  313.  
Jun 26 '10 #1
1 2315
The last too parameters need to be include the out keyword as they're passed by ref, not value. juts put out before the last 2 parameters:

Expand|Select|Wrap|Line Numbers
  1. myrefmethod(out p1 out p3)
Jun 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
2
by: Nuno Esculcas | last post by:
Hello, I come from C++ and i now have to work with C#, and someone tell me that bye bye pointers but i think this is not true, i must convert a DIB image in something that i can use in C# (like...
3
by: dhnriverside | last post by:
Hi I've used a converter to convert from VB.net to C#, and the resulting code uses the namespace Microsoft.VisualBasic.CompilerServices Where can I get this namespace? I can't find it in...
11
by: howa | last post by:
#include<iostream> using namespace std; int main(int argc, char* argv) { cout<<sizeof(argv) / sizeof(argv) ; return 0; };
31
by: Cesar Rodas | last post by:
Hello to all As far I know the unsigned char just use 1-byte, long 4-bytes... is this right??? Well I have the next code... #include <stdio.h> #include <stdlib.h>
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
6
by: Bint | last post by:
I'm getting this returned from a PHP script. What does this mean? <b>Parse error</b>: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in <b>/ho Thanks B
2
by: webinfinite | last post by:
Could anyone explain this snippet for me? #include <iostream> #include <vector> #include <algorithm> using namespace std; class PrintInt { public: void operator() (int elem) const {
4
by: dolphin | last post by:
Hi All I read a .cpp files,find that static void fun(void){......} int main() { .......... } What does this static function mean?Is it the same as the static
3
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.