Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.security.MessageDigest;

public class Main {
    public static String stringGetMD5String(String s) {
        byte[] data;
        MessageDigest md5;

        try {
            data = s.getBytes("UTF-8");
            md5 = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            return null;
        }

        byte[] hash = md5.digest(data);
        StringBuilder hashStr = new StringBuilder();

        for (byte byteValue : hash) {
            hashStr.append(String.format("%02x", byteValue));
        }

        return hashStr.toString();
    }
}