• MD5 in JAVA


    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();
    }

    MD5 Using MessageDigest Class

    jdk自带的,in java.security.MessageDigest Class

    demo代码如下

    @Test
    public void givenPassword_whenHashing_thenVerifying() 
      throws NoSuchAlgorithmException {
        String hash = "35454B055CC325EA1AF2126E27707052";
        String password = "ILoveJava";
             
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(password.getBytes());
        byte[] digest = md.digest();
        String myHash = DatatypeConverter
          .printHexBinary(digest).toUpperCase();
             
        assertThat(myHash.equals(hash)).isTrue();
    }
    作者:jwentest
    虽千万人,吾往矣!文章先发到语雀:https://www.yuque.com/qianwang/testway
  • 相关阅读:
    MetaNamespaceKeyFunc
    golang dlv 调式成员函数
    golang 编译 添加debug gdb
    code-generator
    k8s 自定义informer
    kube-batch ——pod 和task
    kubernetes-handbook informer
    kube batch scheduler
    k8s-scheduler-extender-example
    volcano 快速开始
  • 原文地址:https://www.cnblogs.com/jwentest/p/7066694.html
Copyright © 2020-2023  润新知