【Java/MD5】MD5摘要算法

代码:

package ufo;

import java.security.MessageDigest;

import org.apache.commons.codec.binary.Base64;

public class MD5_Test {
    public static void main(String... args) {
        String original="Let’s Build a Giant Airship 青海长云暗雪山";
        System.out.println("原文=\t"+original);
        
        try {
            // MD5,SHA,SHA-256,SHA-384,SHA-512
            final String ALGORITHM="MD5";
            MessageDigest md=MessageDigest.getInstance(ALGORITHM);
            byte[] digests=md.digest(original.getBytes());
            
            String digestTxt=Base64.encodeBase64String(digests);
            System.out.println("摘要文=\t"+digestTxt);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

输出:

原文=    Let’s Build a Giant Airship 青海长云暗雪山
摘要文=    o3QB396T6wk7Jr6JkTupjg==

END

posted @ 2021-10-13 06:20  逆火狂飙  阅读(49)  评论(0编辑  收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东