in reply to Converting Java to Perl (MD5)
I believe in the Java example you should be applying .getBytes("UTF-8") to the plaintext string; not to the digest. This is because Java strings are UTF-16.
The following two programs both seem to output the same MD5 sum...
use Digest::MD5 'md5_hex'; use Math::BigInt; my $plain = "abcd1234"; my $digest = Math::BigInt::->from_hex(md5_hex $plain); print $digest, "\n";
(Run the above using perl hash.pl.)
import java.security.MessageDigest; import java.math.BigInteger; public class Hash { public static void main( String[] args ) throws Exception { MessageDigest md5 = MessageDigest.getInstance("MD5"); String plain = "abcd1234"; BigInteger digest = new BigInteger(1, md5.digest(plain.getB +ytes("UTF-8"))); System.out.println( digest.abs() ); } }
(Run the above using javac Hash.java && java -cp . Hash.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting Java to Perl (MD5)
by kunimihk (Initiate) on Feb 26, 2013 at 01:29 UTC | |
by tobyink (Canon) on Feb 26, 2013 at 07:46 UTC | |
by kunimihk (Initiate) on Feb 27, 2013 at 01:57 UTC |