2009-12-11 64 views

回答

2
public static void main(final String[] args) throws Exception 
{ 
    final MessageDigest md5 = MessageDigest.getInstance("MD5"); 
    final byte[] digest = md5.digest("Grommit".getBytes("UTF-8")); 
    long result = 0; 
    for (int i = 0; i < 8; i++) 
    { 
     System.out.println(Long.toHexString(0xFFL & digest[i])); 
     result |= (0xFFL & digest[i]) << (i * 8); 
    } 
    System.out.println(Long.toHexString(result)); 
} 
5

試試這個:

MessageDigest md5 = MessageDigest.getInstance("MD5"); 
byte[] digest = md5.digest("Wallace".getBytes("UTF-8")); 
long result = ByteBuffer.wrap(digest).getLong(); 
+0

Booya!關於API的知識勝過了點點滴滴的知識。 +1 –

相關問題