anyone used base64.h in a c++ program?

This is a discussion on anyone used base64.h in a c++ program? within the C++ Programming forums, part of the General Programming Boards category; i am trying to convert username and password to base64 but for some reason i am getting a few compile ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    317

    anyone used base64.h in a c++ program?

    i am trying to convert username and password to base64 but for some reason i am getting a few compile errors, i think i have only the linux version of .base64.h and base64.cpp and not the windows one , can anyone help , TY

    Code:
            string username = "myusername";
    	string passwd = "mypassword";
    	char src[100];
    	char GetBuffer[100];
    	sprintf(GetBuffer,"%s%c%c",username,':',passwd);
    	char *Encoded = encode_base64(sizeof(GetBuffer),(unsigned char *)GetBuffer); //this function is in base64.cpp , the problem is its not compiling properly
    Last edited by Anddos; 03-22-2009 at 08:43 AM.

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    What are the compiler errors?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    error C3861: 'encode_base64': identifier not found

    i look in the .h and dont even see this funciton name

    Code:
    class Base64
      {
        public:
          static std::string encode(const std::string & data);
          static std::string decode(const std::string & data);
          static std::string encodeFromArray(const char * data, size_t len);
        private:
          static const std::string Base64Table;
          static const std::string::size_type DecodeTable[];
      };

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Anddos View Post
    sprintf(GetBuffer,"%s%c%c",username,':',passwd);
    There is something wrong here - %s is for c-strings
    maybe username.c_str() could help

    %c and password do not work together at all

    And why do you try to ancode the whole buffer, while only part of it could contain data?

    Quote Originally Posted by Anddos View Post
    i look in the .h and dont even see this funciton name
    so why are you trying to use internal function that is not been provided as external API?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    so i am trying to access a page that needs login so instead of using base64 from the source i just use a convertor

    char *Http = "GET /index.php/ HTTP/1.1\r\nHost: www.somesite.com\r\n\r\n""Authorization: Basic XXXXXXXXXXXXXXXX"; //so this means i dont have to login???

    this is nothing malicous i am just trying to parse forum posts from a site
    Last edited by Anddos; 03-22-2009 at 10:39 AM. Reason: Had the password in the body - Removed by someone else ;)

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by Anddos View Post
    so i am trying to access a page that needs login so instead of using base64 from the source i just use a convertor

    char *Http = "GET /index.php/ HTTP/1.1\r\nHost: www.somesite.com\r\n\r\n""Authorization: Basic XXXXXXXXXXXXXXXX"; //so this means i dont have to login???

    this is nothing malicous i am just trying to parse forum posts from a site
    Way to go. You had a base64 encoded string baring your username and password for this site. I logged into your account and removed it for you. Be careful - other people might to more malicious things. I hope I was quick enough for you .
    So yes, the base64 encoding was fine :P

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    so why dosent it work?

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Okay, now I actually looked at your post a bit closer, a few things:
    Are you sure you need that kind of authorisation? Most forums don't use HTTP auth, but rather a normal login and a cookie to keep your session's information.

    But if you can, indeed, use http authentication... The Authorization header is... a header . So it should be before the \r\n\r\n. There should be a single \r\n, followed by a \r\n\r\n after the authorization header.

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    well i aso use another way which the reponse is , thanks for logging in

    sprintf(body,"vb_login_username=Anddos&cookieuser= 1&vb_login_password=&s=&do=login&vb_login_md5passw ord=34507f68ddd44f5c1fr99c9ed5e73644& vb_login_md5password_utf=34507f68ddd44f5c1f299c9ed 5e73644");
    sprintf(headers, "POST /login.php?do=login HTTP/1.1\r\nHost: www.somesite.com\r\n"
    "Connection: Keep-Alive\r\n"
    "KeepAliveTimeout: 15\r\n"
    "Content-Type: application/x-www-form-urlencoded\r\n"
    "Content-Length: %i\r\n\r\n", strlen(body));

    after this i dont know how to use GET to get the pages i should be able to access after logging in, it just seems to loose connection or something

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    You just don't learn do you..? I mean, posting your password in base64 format is really bad and granted, posting it md5 is a little bit better. But it's still bad - and brute forceable.

    I suggest you change your password asap

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    317
    this code works perfect, the trouble is after this , i cant do anything....

    Code:
    sprintf(body,"vb_login_username=Anddos&cookieuser=1&vb_login_password=&s=&do=login&vb_login_md5password=34507f68ddd44f5c1f299c9ed5e73644&vb_login_md5password_utf=34507f68ddd44f5c1f299c9ed5e73644");
    	sprintf(headers, "POST /login.php?do=login HTTP/1.1\r\nHost: www.site.com\r\n"
    		             "Connection: Keep-Alive\r\n"
    					 "KeepAliveTimeout: 15\r\n"
                         "Content-Type: application/x-www-form-urlencoded\r\n"
    					 "Content-Length: %i\r\n\r\n", strlen(body));
    oh and the dude say about my password , well so what i didnt think of changing it at the time , why would you want to abuse a forum account ...

    anyone after this request it logs in fine , after that i do
    char *index = "GET /index.php HTTP/1.1\r\nHost: www.site.com\r\n;
    send(sock,index,strlen(index),0); after this recv goes to 0 .....
    Last edited by Anddos; 03-22-2009 at 04:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21