wrote in
news: oups.com:
> I need to match md5 outputs being generated by a java app which in
> relevent part uses the following code:
>
> byte[] digest = md.digest();
>
> for (int i=0;i<digest.length;i++) {
>
> hexString.append(Integer.toHexString(digest[i] & 0xFF));
>
> }
>
> return hexString.toString();
>
> where md is an instance of MessageDigest.getInstance("MD5");
>
> Using a particular value to be encoded, this function returns the
> 31-digit hexedecimal string
>
> a1ee2c082ee66978aeca3d377fd11a5
>
> Using the perl Digest::MD5 md5_hex function on the same string returns
> thie following 32-digit hexidecimal string, which is the same as the
> java output with a leading "0" added.
>
> 0a1ee2c082ee66978aeca3d377fd11a5
>
> I can't change the java so I am trying to to re-create the java
> results using perl. I've been using various permutations of unpack
> and sprintf on the 16-bit binary value generated by Digest::MD5 md5
> without success so far.
I am not sure what 16-bit value you are talking about. MD5 produces a
128-bit digest.
I am not exactly sure what you are trying to do, but ...
Are you just trying to remove leading zeros?
#!/usr/bin/perl
use strict;
use warnings;
my $md5 = '0a1ee2c082ee66978aeca3d377fd11a5';
$md5 =~ s{\A 0+ }{}x;
print "$md5\n";
__END__
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html