From 9e48c6f7d602364eb1c18de7e1e4c00e4852839c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 4 Aug 2009 05:24:13 +0000 Subject: ***IMPORTANT*** The function Bu::Md5::getResult no longer returns a hex string, it returns the raw binary string that makes up the md5 sum, this matches the original goal of the API and makes the whole system more general and transportable. I have added a handy helper function named getHexResult that will return the same classic hex md5 string we're used to, change anything in your code that uses getResult to getHexResult now. I've also added a handy function to the CryptoHash to write the result to a stream, writeResult. I've fixed some more things in the formatter, and added a cryptPass function that works very much like the system crypt function, md5 and base64. If I knew more about the glibc implementation I could probably make them compatible. For now there are some subtle differences in the formatting and the salting algorithm, also the output mantains it's base64 trailer (==) wheras the system function chops those off. There's also another helper that will only work on linux for now, that only takes the password, and generates a salt for you using urandom. --- src/tests/cryptpass.cpp | 18 ++++++++++++++++++ src/tests/md5.cpp | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/tests/cryptpass.cpp (limited to 'src/tests') diff --git a/src/tests/cryptpass.cpp b/src/tests/cryptpass.cpp new file mode 100644 index 0000000..4b090fe --- /dev/null +++ b/src/tests/cryptpass.cpp @@ -0,0 +1,18 @@ +#include "bu/crypt.h" +#include "bu/sio.h" + +using namespace Bu; + +int main( int argc, char *argv[] ) +{ + if( argc == 1 ) + sio << "Syntax: " << argv[0] << " [salt]" << sio.nl + << sio.nl; + else if( argc == 2 ) + sio << "Crypt1: >> " << cryptPass( argv[1] ) << " <<" << sio.nl; + else + sio << "Crypt2: >> " << cryptPass( argv[1], argv[2] ) << " <<" << sio.nl; + + return 0; +} + diff --git a/src/tests/md5.cpp b/src/tests/md5.cpp index 3b3d5e7..69ddd1d 100644 --- a/src/tests/md5.cpp +++ b/src/tests/md5.cpp @@ -28,7 +28,7 @@ int main( int argc, char *argv[] ) break; } - sio << m.getResult() << " *" << *argv << sio.nl; + sio << m.getHexResult() << " *" << *argv << sio.nl; } } -- cgit v1.2.3