using Apache Commons
需要引入org.apache.commons.codec.digest.DigestUtils这个包,pom.xml文件配置如下:
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.10</version> </dependency>
demo代码如下:
@Test public void givenPassword_whenHashingUsingCommons_thenVerifying() { String hash = "35454B055CC325EA1AF2126E27707052"; String password = "ILoveJava"; String md5Hex = DigestUtils .md5Hex(password).toUpperCase(); assertThat(md5Hex.equals(hash)).isTrue(); }
时间: 2024-10-14 11:45:22