Last active
May 9, 2018 07:17
-
-
Save tonfever/59972e52d5a8f85eac85255b062a5d86 to your computer and use it in GitHub Desktop.
Generate MD5 message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.codec.digest.DigestUtils; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import javax.xml.bind.DatatypeConverter; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
public class Md5UtilTest{ | |
private String message = "Hello world"; | |
@Test | |
public void testMd5WithApacheCommonsCodec() { | |
Assert.assertEquals("3e25960a79dbc69b674cd4ec67a72c62",DigestUtils.md5Hex(message)); | |
} | |
@Test | |
public void testMd5WithSpringUtil() { | |
Assert.assertEquals("3e25960a79dbc69b674cd4ec67a72c62",org.springframework.util.DigestUtils.md5DigestAsHex(message.getBytes())); | |
} | |
@Test | |
public void testMd5WithJavaSecurity() throws NoSuchAlgorithmException { | |
MessageDigest messageDigest = MessageDigest.getInstance("MD5"); | |
messageDigest.update(message.getBytes()); | |
byte[] digest = messageDigest.digest(); | |
Assert.assertEquals("3E25960A79DBC69B674CD4EC67A72C62", DatatypeConverter.printHexBinary(digest)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment