开发者

MessageDigest SHA-512 different than openssl

I can't figure out what I'm doing wrong here. I have the following code:

byte[] digest = new byte[0];
MessageDigest md = null;
try{
    md = MessageDigest.getInstance( "SHA-512" );
}
catch( NoSuchAlgorithmException e ) {
    return digest;
}
digest = md.digest( myString.getBytes() );

Looking at the hex values of digest byte[] in the NetBeans debugger, it shows something different than the output of:

echo "myString" | openssl dgst -sha512

I'm guessing it's a character encoding issue, but doesn't the JVM and openssl use the default character set for 开发者_如何学Cthe machine?

Any help is appreciated.


echo appends a newline at the end -

[steven@emu:~]% echo "myString" | hexdump -C
00000000  6d 79 53 74 72 69 6e 67  0a                       |myString.|

Try echo -n?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜