Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » md5digest format
md5digest format [message #10279] Fri, 29 June 2007 11:45 Go to next message
atmks is currently offline  atmks
Messages: 33
Registered: July 2006
Member
hi

how do i convert result of MD5Digest("blabla") to human readable format(32 byte long string)?

thx
Re: md5digest format [message #10280 is a reply to message #10279] Fri, 29 June 2007 11:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, not that I like that Tom's interface too much...

Anyway, what you get is MD5 as 16 binary bytes stored in String.

What you need to do is to convert them one by one to hex to get the result.

E.g. (not quite optimal speedwise):

String x = MD5Digets(...);
String r;
for(int i = 0; i < x.GetCount(); i++)
  r << FormatIntHex(x[i], 2); 


should work.
Re: md5digest format [message #10281 is a reply to message #10280] Fri, 29 June 2007 12:27 Go to previous messageGo to next message
atmks is currently offline  atmks
Messages: 33
Registered: July 2006
Member
thx for the fast answer, but the code doesn't work,

program does create very long string, aprox 70-80 char

	String x = MD5Digest("alajos");
	String r;
	for(int i = 0; i < x.GetCount(); i++) {
		r << FormatIntHex(x[i], 2);
	}
	
	Cout() << r << '\n';


result:
4c681e2952ffffff88ffffffbfffffffde2058360bffffffb2ffffffddffffffe6ffffffbb
Re: md5digest format [message #10282 is a reply to message #10279] Fri, 29 June 2007 12:45 Go to previous messageGo to next message
atmks is currently offline  atmks
Messages: 33
Registered: July 2006
Member
this code does work, but very ugly Smile

	String x = MD5Digest("alajos");
	String r;
	for(int i = 0; i < x.GetCount(); i++) {
		int a = 0;
		char * ptr = (char*)&a;
		*ptr = x[i];
		r << FormatIntHex(a, 2);
	}
	
	Cout() << r << '\n';

[Updated on: Fri, 29 June 2007 12:48]

Report message to a moderator

Re: md5digest format [message #10283 is a reply to message #10282] Fri, 29 June 2007 16:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sorry:

	String x = MD5Digest("alajos");
	String r;
	for(int i = 0; i < x.GetCount(); i++)
		r << FormatIntHex((byte)x[i], 2);


(need to cast to (byte), otherwise char converts to negative integers...)

Mirek
Re: md5digest format [message #10310 is a reply to message #10283] Sun, 01 July 2007 20:08 Go to previous message
atmks is currently offline  atmks
Messages: 33
Registered: July 2006
Member
thx Cool
Previous Topic: Ultimate++ and SSH/SFTP ?
Next Topic: GetHomeDirectory() not supported on Windows?
Goto Forum:
  


Current Time: Tue Apr 23 17:16:50 CEST 2024

Total time taken to generate the page: 0.02240 seconds