1

Possible Duplicate:
In C++, How to get MD5 hash of a file?

I am currently using Ubuntu and am wishing to calculate the MD5 of a char*. was wondering if there is a pre-installed library that would just need including, or would I have to download a specially designed one?

Community
  • 1
  • 1
Opal
  • 1,057
  • 8
  • 27

3 Answers3

5

Include openssl/MD5.h and use the following to calculate the hash

MD5(<characters>, <length of it>, <the result(pointer)>);
Opal
  • 1,057
  • 8
  • 27
1

Have a look at hashlib++ or Crypto API.

Exa
  • 4,020
  • 7
  • 43
  • 60
-3

I would rephrase the question. In the context of C++, you're asking for the MD5 sum of a single pointer to char, which is practically meaningless.

That 'char *' could refer to a location in memory that refers to the file content you are after, in which case you're going to need a size somewhere, or it could refer to a null-terminated string, or a pascal-string, or, really, anything else.

With ubuntu, I'd do something like 'apt-cache search md5' and see what you get. On my debian system, libgcrypt11 looks intriguing.

Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
Arafangion
  • 11,517
  • 1
  • 40
  • 72
  • 2
    Most C/C++ programmers understand that normally char * refers to a NULL terminated string. It could mean other things but no need to be so pedantic. – bradgonesurfing Aug 06 '10 at 07:52
  • Actually, in C++, it probably more often refers to an arbituary chunk of memory - a 'char' being used as a generic byte type. One would normally use std::string instead. This is C++, not C. – Arafangion Aug 06 '10 at 23:35
  • And don't forget, I actually show how to find this information yourself, ie, make use of the package manager - AND, I give a promising result that could be useful. – Arafangion Aug 06 '10 at 23:36