LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-20-2007, 11:38 PM   #1
erat123
Member
 
Registered: Oct 2006
Distribution: Ubuntu
Posts: 69

Rep: Reputation: 16
crypto++


hi guys, I've been doing research all day long and havent really found anything yet. i'm building a web server and i need to use a hash algorithm for passwords. i would like to program this in c++. i've been looking at crypto++ and i would really like to use sha512. does anyone know where i can find a GOOD working example of this or another related algorithm in c++?
 
Old 01-21-2007, 12:07 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I would strongly suggest you just link with openssl and use its built-in hashing functions.
 
Old 01-21-2007, 12:09 AM   #3
erat123
Member
 
Registered: Oct 2006
Distribution: Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 16
could you give me an example of that please?
 
Old 01-21-2007, 12:24 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Well, for md5:
Code:
#include <openssl/md5.h>
#include <string.h>

char *md5sum(char *pw){
    static char strbuf[33];
    char buf[16];
    int i;

    strbuf[0] = '\0';
    MD5(pw,strlen(pw),buf);

    for(i=0;i<16;i++)
        sprintf(strbuf,"%s%02x",strbuf,buf[i]);

    return strbuf;
}
This will return the hex form of the MD5 hash as a static char *.
 
Old 01-21-2007, 01:51 AM   #5
erat123
Member
 
Registered: Oct 2006
Distribution: Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 16
Thanks for the sample code. I tried it out and changed it a little and I'm having some problems with it.


Code:
#include <stdio.h>
#include <openssl/md5.h>
#include <string.h>
#include <iostream>
using namespace std;

char *md5sum(char *pw){
    static char strbuf[33];
    char buf[16];
    int i;

    strbuf[0] = '\0';
    MD5((const unsigned char*)pw,strlen(pw),(unsigned char*)buf);

    for(i=0;i<16;i++)
        sprintf(strbuf,"%s%02x",strbuf,buf[i]);

    return strbuf;
}

int main()
{
	char *x = "test";
	md5sum(x);
	return 0;
}
It compiled fine, but it gives me a permission denied error. Do you see anything wrong with the code? Also, here is the line I used to compile:

Code:
eric@eric-desktop:~/Desktop$ g++ -w -pipe -c encrypt.cpp -o md5.exe
eric@eric-desktop:~/Desktop$ ./md5.exe
bash: ./md5.exe: Permission denied

Last edited by erat123; 01-21-2007 at 01:55 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for ieee80211 and Crypto?? yttrium88 Linux - Newbie 3 05-06-2020 07:46 AM
Crypto Formula rubadub Programming 2 09-06-2006 10:16 AM
Crypto problems Slacker0815 Linux - Security 10 02-09-2004 12:24 AM
Crypto Challenge jeremy Linux - Security 2 11-18-2003 07:56 AM
UK - DTI Goes Crypto Crazy jharris General 0 05-22-2003 05:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration