Consistent cross platform message digests using SHA-1?
I've been experimenting with the SHA-1 and MD5 implementations in JDK 1.4.
There is some sample code in IBM DeveloperWorks, with sample results for
a simple string: "This is a test!" yielding an SHA-1 message digest of
D93,.x2%$kd8xdp3di5*
Trying to duplicate the results on a Sun box, I just got a bunch of garble
instead of the expected 160 bit (20 character) digest. When I write the output
to a file, at least the length of the digest is correct - but doesn't match
the expected value.
The basic question is - can the Java implementations of SHA-1 and MD5 be
used in a manner by which the same results can reliably be generated regardless
of platform (NT, Sun, HP, AIX, etc.) and code-page?
# 1 Re: Consistent cross platform message digests using SHA-1?
Hello!
I think the problem was in using different codepages for same message
in different platform. Because SHA-1 and MD5 message digests use OCTET
STRING to calculate value. Therefore OCTET STRING presentment should by
same in different platforms. I think there is only one way - use UNICODE
for such strings. This is supported by Java SDK and by many other computer
environments. If in UNICODE presentment you'll get different results -
therefore problem in implementation MD5 and SHA-1 algorithm in corresponding
platforms.
Best regards,
Nikolay Stanchenko,
Brainbench MVP in Internet Security
"Larry Leeth" <enterprise.@127.0.0.1> wrote:
>
>I've been experimenting with the SHA-1 and MD5 implementations in JDK 1.4.
>There is some sample code in IBM DeveloperWorks, with sample results for
>a simple string: "This is a test!" yielding an SHA-1 message digest of
>D93,.x2%$kd8xdp3di5*
>
>Trying to duplicate the results on a Sun box, I just got a bunch of garble
>instead of the expected 160 bit (20 character) digest. When I write the
output
>to a file, at least the length of the digest is correct - but doesn't match
>the expected value.
>
>The basic question is - can the Java implementations of SHA-1 and MD5 be
>used in a manner by which the same results can reliably be generated regardless
>of platform (NT, Sun, HP, AIX, etc.) and code-page?