in reply to Java to perl conversion
Digest::MD5 doesn't take an array; it takes a string.
If simply passing your strings to Digest::MD5::md5() does not produce the same 16-byte value that the Java code is producing, it will be because the Java code is digesting the entire 256-byte packet including the trailing nulls.
Therefore the solution is to pad the string to 256-bytes with nulls before generating the md5:
my $string = ...; # get the string from wherever $string = pack 'a256', $string; ## Will null pad to the specified leng +th my $md5 = md5( $string ); ... do the twofish stuff.
That doesn't deal with strings that start out greater than 256, but neither does the Java code.
It will also not correctly deal with strings where char != byte.
If that is a requirement, the simplest solution will be to turn off the utf flag before the pack, but there is undoubtedly a (suite of) modules that will do the same thing.
|
|---|