SHA1 and MD5

Discussion in 'Mac Programming' started by fernandovalente, Jan 25, 2010.

  1. fernandovalente macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #1
    I know this is really foolish, but unfortunately, I don't know how to do that. I need to hash strings using SHA1 and MD5. How may I do that?

    EDIT: I forgot to say that I need to use RSA for that. I got no idea of how I can do that.
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Google keywords:
    sha1 mac os x
    md5 mac os x

    If those results aren't what you want, then please be more specific. For example, what programming language?

    We can't read your mind to understand the context of your question. Nor can we always assume that your latest question is a follow-up to one of your previous questions.

    http://www.cocoadev.com/index.pl?HowToAskQuestions

    http://www.mikeash.com/getting_answers.html

    After reading those, you might want to bookmark this page:
    http://www.cocoadev.com/index.pl

    and use it to search CocoaDev for keywords like sha1 or md5.
     
  3. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #3
    I tried to Google for that, but I couldn't find what I wanted.

    I'm using Objective-C. I want to hash strings using SHA1 with a RSA key hash strings with MD5. I'm on Snow Leopard with Xcode 3.2.1.
     
  4. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #4
    Try:

    % man 3 SHA1

    It should give you something that looks somewhat like this:

    http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man3/SHA1.3ssl.html

    Code:
            #include <openssl/sha.h>
    
            unsigned char *SHA1(const unsigned char *d, unsigned long n,
                             unsigned char *md);
    

    % man 3 md5

    http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man3/md5.3ssl.html

    Code:
            #include <openssl/md5.h>
    
            unsigned char *MD5(const unsigned char *d, unsigned long n,
                             unsigned char *md);
    

    So basically, the function names are "SHA1" and "MD5."




    ...and hope to god you don't have to do the same thing on Windows.
     
  5. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #5
    I still can't get it to work. Sorry for the n00b question(I never did anything with SHA1 and MD5). How may I print the generated hash on console? How may I set a string to be hashed?

    NSLog(@"%@", whatgoeshere?);
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Then try googling with something else that might be more relevant. For example, the computer language you're writing in, or the framework you're using. Like:
    sha1 objective c
    sha1 cocoa


    And also try searching the cocoadev site, using the URL I gave previously.
     
  7. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #7
    It gives you BINARY (20 bytes == 160 bits). It's not a string to be printed. I don't know if NSLog handles all of printf's format strings, but "%x" is how you tell printf you want your 32-bit integer to display as hexadecimal.

    see:

    % man 3 printf
     
  8. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #9
    In doing your search, you must have realized that all of this is in the OpenSSL library on the Mac. Search developer sites, search library sites, and SEARCH MAN PAGES (apropos).
     
  9. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #10
    Of course not. I didn't write code for you. Do you understand what is meant by "a pointer to 20 bytes of memory," or by "string concatenation"
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #11
    I'll repeat my earlier suggestion when you were asking about license-registration software:
    Read the source of Aquatic Prime.

    If you don't understand what it's doing, then you need to get to the point where you do.

    You need to know the fundamentals perfectly. If you can't figure out how to call a C function, then you need to work on that before trying something more complex.

    You also need to post your code. "Still no luck" is not debuggable. It's not even compilable.

    http://whathaveyoutried.com/
     
  11. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #12
  12. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  13. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #14
    Tried this for MD5:

    unsigned char *MD5(const unsigned char *d, unsigned long n,
    unsigned char *md);
     
  14. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #15
    You'll need to post more than that....
     
  15. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #16
    That only declares a function. It doesn't produce any code.

    In fact, it looks exactly like the declaration of openssl's MD5 function, as provided by its man page (man 3 md5).

    We need to see your code. The code that defines your variables and then calls openssl's MD5 function.
     
  16. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #17
    I want to set a value to be encrypted and get the value it returns.
     
  17. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #18
    Try posting actual code rather than just copying function prototypes.

    From the sounds of it you really need to go back and study C and Objective-C properly.
     
  18. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #19
    I'm still studding them. :/
     
  19. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #20
    This doesn't add up. You appear to be shipping four iPhone apps, yet you don't know how to call a C function? Or didn't you write those four iPhone apps?

    If you didn't write the apps, and you don't know C, then you should probably pick a simpler project than an uncrackable license-key enforcement system.

    My only intent is to be honest about this, not nasty, but it looks like you don't have the necessary skills at this time.
     
  20. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #21
    Yes, I wrote the four apps you see in my signature. 100% of the code was wrote by me. Believe or not, I'm a C n00b. I know more about C++ than I know about C. I know Objective-C(I'm not an expert), but I don't know C yet. I will start studding C soon. I don't wanna write an uncrackable license-key enforcement system, but a decent one. :/
     
  21. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #22
    I found the problem. Call me idiot, I deserve it. I read the documentation only once. I thought they were variables. I know you're gonna laugh and say I'm an idiot, I really deserve it. I guess I need to pay more attention at thing I read. Sorry guys. :(
     
  22. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #23
    Seeing as Objective-C is a superset of C then by definition if you know Objective-C you also know C.

    The only thing I can suggest is that you work on both your Objective-C and C skills. This is all fundamental stuff we are talking about here.
     
  23. fernandovalente thread starter macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #24
    Sorry for all posts made on this thread. I really need to pay more attention at thing I read. Yes, I know about Objective-C being a superset of C. I'm working on them. I'm learning something new each day. :)
     
  24. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #25
    Don't get me wrong. People on this site are very willing to help but you need to phrase your questions correctly to get the help that you want. You also need to show what you have done yourself otherwise people will assume you are trying to freeload.

    Keep reading and keep asking and you'll get there soon enough :).
     

Share This Page